Skip to content

Commit

Permalink
fix(eslint-config): issues within ts and js config
Browse files Browse the repository at this point in the history
We were using babel-plugin for both js and ts related configs. We
would need it only on js config, and not the ts config.

Also remove some extends from template to individual files for
proper ordering.
  • Loading branch information
swashata committed Apr 15, 2019
1 parent 7f05a9d commit 33c0661
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 70 deletions.
9 changes: 1 addition & 8 deletions packages/eslint-config/config/extends.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
// Default extends (from where we inherit our config)

module.exports = [
'airbnb',
'plugin:jest/recommended',
'plugin:prettier/recommended',
'prettier',
'prettier/react',
'prettier/babel',
];
module.exports = ['airbnb', 'plugin:jest/recommended'];
63 changes: 4 additions & 59 deletions packages/eslint-config/config/rules.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,12 @@
// Default sets of rules for ESLint

module.exports = {
// ===================================
// Some rules from eslint-plugin-babel
// ===================================
// First turn them off
'new-cap': 'off',
camelcase: 'off',
'no-invalid-this': 'off',
'object-curly-spacing': 'off',
semi: 'off',
'no-unused-expressions': 'off',
'valid-typeof': 'off',
// require a capital letter for constructors
'babel/new-cap': [
'error',
{
newIsCap: true,
newIsCapExceptions: [],
capIsNew: false,
capIsNewExceptions: [
'Immutable.Map',
'Immutable.Set',
'Immutable.List',
],
},
],
// require camel case names
// This one is enhanced from airbnb and accounts for destructuring
// and react UNSAFE_component* methods.
'babel/camelcase': [
'error',
{
properties: 'never',
ignoreDestructuring: true,
},
],
// We would force invalid this rules
// But would only warn about it
'babel/no-invalid-this': 'warn',
// We don't configure curly spacing because of prettier
'babel/object-curly-spacing': 'off',
// We don't configure babel/semi because of prettier
'babel/semi': 'off',
// disallow usage of expressions in statement position
'babel/no-unused-expressions': [
'error',
{
allowShortCircuit: false,
allowTernary: false,
allowTaggedTemplates: false,
},
],
// ensure that the results of typeof are compared against a valid string
// https://eslint.org/docs/rules/valid-typeof
'babel/valid-typeof': ['error', { requireStringLiterals: true }],
'react/no-unused-prop-types': 1,
'react/no-unused-state': 1,
'no-unused-vars': 1,
'react/no-unused-prop-types': 'warn',
'react/no-unused-state': 'warn',
'prettier/prettier': ['error'],
'no-console': 0,
'no-console': 'warn',
'no-plusplus': [
2,
'error',
{
allowForLoopAfterthoughts: true,
},
Expand Down
63 changes: 62 additions & 1 deletion packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ const ex = require('./config/extends');

module.exports = {
env,
extends: ex,
extends: [
...ex,
'prettier/babel',
'plugin:prettier/recommended',
'prettier',
'prettier/react',
],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
Expand All @@ -23,5 +29,60 @@ module.exports = {
plugins: ['babel'],
rules: {
...rules,
// ===================================
// Some rules from eslint-plugin-babel
// ===================================
// First turn them off
'new-cap': 'off',
camelcase: 'off',
'no-invalid-this': 'off',
'object-curly-spacing': 'off',
semi: 'off',
'no-unused-expressions': 'off',
'valid-typeof': 'off',
// require a capital letter for constructors
'babel/new-cap': [
'error',
{
newIsCap: true,
newIsCapExceptions: [],
capIsNew: false,
capIsNewExceptions: [
'Immutable.Map',
'Immutable.Set',
'Immutable.List',
],
},
],
// require camel case names
// This one is enhanced from airbnb and accounts for destructuring
// and react UNSAFE_component* methods.
'babel/camelcase': [
'error',
{
properties: 'never',
ignoreDestructuring: true,
},
],
// We would force invalid this rules
// But would only warn about it
'babel/no-invalid-this': 'warn',
// We don't configure curly spacing because of prettier
'babel/object-curly-spacing': 'off',
// We don't configure babel/semi because of prettier
'babel/semi': 'off',
// disallow usage of expressions in statement position
'babel/no-unused-expressions': [
'error',
{
allowShortCircuit: false,
allowTernary: false,
allowTaggedTemplates: false,
},
],
// ensure that the results of typeof are compared against a valid string
// https://eslint.org/docs/rules/valid-typeof
'babel/valid-typeof': ['error', { requireStringLiterals: true }],
'no-unused-vars': 'warn',
},
};
11 changes: 9 additions & 2 deletions packages/eslint-config/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ const ex = require('./config/extends');
module.exports = {
env,
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended',
...ex,
'plugin:prettier/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/react',
'prettier/@typescript-eslint',
],
parser: '@typescript-eslint/parser',
plugins: ['babel'],
rules: {
...rules,
// turn off react prop-types because we will be using typescript
'react/prop-types': 'off',
'react/require-default-props': 'off',
'react/default-props-match-prop-types': 'off',
'react/no-unused-prop-types': 'off',
// typescript specific rules
'import/prefer-default-export': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
Expand Down

0 comments on commit 33c0661

Please sign in to comment.