Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from adambrgmn/develop
Browse files Browse the repository at this point in the history
Update Eslint config
  • Loading branch information
adambrgmn authored Nov 29, 2017
2 parents 9144e79 + 231796c commit ff7d853
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 17 deletions.
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
}
18 changes: 2 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
53 changes: 53 additions & 0 deletions src/config/__tests__/eslintrc.js
Original file line number Diff line number Diff line change
@@ -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 }) => (
<button {...rest}>{children}</button>
);
`);

expect(result.errorCount).toBeLessThan(1);
});
22 changes: 21 additions & 1 deletion src/config/eslintrc.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
1 change: 1 addition & 0 deletions src/scripts/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const useBuiltinConfig =
!args.includes('--config') &&
!hasFile('.eslintrc') &&
!hasFile('.eslintrc.js') &&
!hasFile('.eslintrc.json') &&
!hasPkgProp('eslintConfig');

const config = useBuiltinConfig
Expand Down

0 comments on commit ff7d853

Please sign in to comment.