diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..3164c2a --- /dev/null +++ b/.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": ["./src/config/eslintrc.js"], + "rules": { + "global-require": "off", + "no-process-exit": "off", + "import/no-dynamic-require": "off", + "import/no-unassigned-import": "off", + "no-console": "off", + "no-nested-ternary": "off" + } +} diff --git a/package.json b/package.json index b3dacab..5d315ca 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "all-contributors-cli": "^4.9.1", "arrify": "^1.0.1", "babel-cli": "^6.26.0", + "babel-eslint": "^8.0.2", "babel-jest": "^21.2.0", "babel-macros": "^1.2.0", "babel-plugin-external-helpers": "^6.22.0", @@ -63,6 +64,7 @@ "eslint-config-airbnb": "^16.1.0", "eslint-config-airbnb-base": "^12.1.0", "eslint-config-prettier": "^2.9.0", + "eslint-plugin-babel": "^4.1.2", "eslint-plugin-import": "^2.8.0", "eslint-plugin-jsx-a11y": "^6.0.2", "eslint-plugin-react": "^7.5.1", @@ -94,22 +96,6 @@ "jest-in-case": "^1.0.2", "slash": "^1.0.0" }, - "eslintConfig": { - "extends": ["airbnb-base", "prettier"], - "env": { - "node": true, - "jest": true - }, - "rules": { - "global-require": "off", - "no-process-exit": "off", - "import/no-dynamic-require": "off", - "import/no-unassigned-import": "off", - "no-console": "off", - "no-nested-ternary": "off" - } - }, - "eslintIgnore": ["node_modules", "coverage", "dist"], "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog" diff --git a/src/config/__tests__/eslintrc.js b/src/config/__tests__/eslintrc.js new file mode 100644 index 0000000..13e1571 --- /dev/null +++ b/src/config/__tests__/eslintrc.js @@ -0,0 +1,53 @@ +import { CLIEngine } from 'eslint'; +import baseConfig from '../eslintrc'; + +jest.mock('../../utils', () => ({ + ...require.requireActual('../../utils'), + ifAnyDep: jest.fn((key, t) => t), +})); + +const cli = new CLIEngine({ + useEslintrc: false, + baseConfig, +}); + +const lint = code => { + const linter = cli.executeOnText(code); + return linter.results[0]; +}; + +afterEach(() => { + jest.resetModules(); +}); + +test('Understands class properties', () => { + const result = lint(` + export class Bar { + constructor() { + this.bar = 'foo'; + } + + setFoo = f => { + this.foo = f; + } + + getFoo(){ + return this.bar; + } + } + `); + + const filtered = result.messages.filter(m => m.fatal); + expect(filtered.length).toBeLessThan(1); +}); + +test('Understands jsx', () => { + const result = lint(` + /* eslint-disable react/prop-types, react/react-in-jsx-scope */ + export const Comp = ({ children, ...rest }) => ( + + ); + `); + + expect(result.errorCount).toBeLessThan(1); +}); diff --git a/src/config/eslintrc.js b/src/config/eslintrc.js index dea80a9..5aa5644 100644 --- a/src/config/eslintrc.js +++ b/src/config/eslintrc.js @@ -1,10 +1,30 @@ const { ifAnyDep } = require('../utils'); module.exports = { + parser: 'babel-eslint', extends: [ require.resolve('eslint-config-airbnb-base'), ifAnyDep('react', require.resolve('eslint-config-airbnb')), require.resolve('eslint-config-prettier'), ].filter(Boolean), - rules: {}, + plugins: ['babel'], + env: { + browser: true, + node: true, + commonjs: true, + 'shared-node-browser': true, + es6: true, + worker: true, + jest: true, + }, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + ecmaFeatures: { experimentalObjectRestSpread: true }, + }, + rules: { + 'import/prefer-default-export': 'off', + 'react/jsx-filename-extension': 'off', + 'react/sort-comp': 'off', + }, }; diff --git a/src/scripts/lint.js b/src/scripts/lint.js index e9a7eb9..31c3b10 100644 --- a/src/scripts/lint.js +++ b/src/scripts/lint.js @@ -12,6 +12,7 @@ const useBuiltinConfig = !args.includes('--config') && !hasFile('.eslintrc') && !hasFile('.eslintrc.js') && + !hasFile('.eslintrc.json') && !hasPkgProp('eslintConfig'); const config = useBuiltinConfig