Compare commits

...

3 Commits

Author SHA1 Message Date
Jordan Harband
39744d8368 diffs from running autofix 2020-03-12 15:34:02 -07:00
Sharmila
89facb451e [Breaking] add “base”, add “rules/prettier”, break index to require prettier
Co-authored-by: Sharmila <tosharmila@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2020-02-15 15:20:04 -08:00
Jordan Harband
cb9707fffb [Tests] actually run the linter on subpackages 2020-03-12 15:41:30 -07:00
17 changed files with 707 additions and 492 deletions

View File

@@ -10,8 +10,8 @@ before_install:
install:
- 'if [ -n "${PACKAGE-}" ]; then cd "packages/${PACKAGE}"; fi'
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
- 'if [ -n "${ESLINT}" ]; then npm install --no-save "eslint@${ESLINT}"; fi'
- 'if [ -n "${REACT_HOOKS}" ]; then npm install --no-save "eslint-plugin-react-hooks@${REACT_HOOKS}"; fi'
- 'if [ -n "${ESLINT-}" ]; then npm install --no-save "eslint@${ESLINT}"; fi'
- 'if [ -n "${REACT_HOOKS-}" ]; then npm install --no-save "eslint-plugin-react-hooks@${REACT_HOOKS}"; fi'
script:
- 'if [ -n "${PREPUBLISH-}" ]; then npm run pretravis && npm run prepublish && npm run posttravis; elif [ -n "${LINT-}" ]; then npm run lint; else npm run travis; fi'
sudo: false
@@ -26,12 +26,16 @@ env:
matrix:
fast_finish: true
include:
- node_js: "lts/*"
env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb-prettier
- node_js: "lts/*"
env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb-base
- node_js: "lts/*"
env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb
- node_js: "lts/*"
env: PREPUBLISH=true ESLINT=6 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- node_js: "lts/*"
env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-prettier
- node_js: "lts/*"
env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
- node_js: "lts/*"
@@ -40,6 +44,10 @@ matrix:
env: PREPUBLISH=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- node_js: "lts/*"
env: LINT=true
- node_js: "lts/*"
env: LINT=true PACKAGE=eslint-config-airbnb
- node_js: "lts/*"
env: LINT=true PACKAGE=eslint-config-airbnb-base
- node_js: "7"
env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
- node_js: "7"

View File

@@ -1,8 +1,4 @@
{
"root": true,
"extends": "./index.js",
"rules": {
// disable requiring trailing commas because it might be nice to revert to
// being JSON at some point, and I don't want to make big changes now.
"comma-dangle": 0,
},
}

View File

@@ -0,0 +1,17 @@
module.exports = {
extends: [
'./rules/best-practices',
'./rules/errors',
'./rules/node',
'./rules/style',
'./rules/variables',
'./rules/es6',
'./rules/imports',
'./rules/strict',
].map(require.resolve),
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {},
};

View File

@@ -1,17 +1,3 @@
module.exports = {
extends: [
'./rules/best-practices',
'./rules/errors',
'./rules/node',
'./rules/style',
'./rules/variables',
'./rules/es6',
'./rules/imports',
'./rules/strict',
].map(require.resolve),
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {},
extends: ['./base', './rules/prettier'].map(require.resolve),
};

View File

@@ -4,30 +4,35 @@ module.exports = {
'./rules/errors',
'./rules/node',
'./rules/style',
'./rules/variables'
'./rules/variables',
].map(require.resolve),
env: {
browser: true,
node: true,
amd: false,
mocha: false,
jasmine: false
jasmine: false,
},
rules: {
'comma-dangle': ['error', 'never'],
'prefer-numeric-literals': 'off',
'no-restricted-properties': ['error', {
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
}, {
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
}, {
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
}],
'no-restricted-properties': [
'error',
{
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
},
{
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
},
{
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
},
],
'no-var': 'off',
strict: ['error', 'safe'],
}
},
};

View File

@@ -60,19 +60,23 @@
"eslint": "^5.16.0 || ^6.7.2",
"eslint-find-rules": "^3.4.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-prettier": "^3.1.2",
"in-publish": "^2.0.0",
"safe-publish-latest": "^1.1.4",
"tape": "^5.0.0-next.4"
},
"peerDependencies": {
"eslint": "^5.16.0 || ^6.7.2",
"eslint-plugin-import": "^2.20.1"
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-prettier": "^3.1.2"
},
"engines": {
"node": ">= 6"
"node": ">= 8.10"
},
"dependencies": {
"confusing-browser-globals": "^1.0.9",
"eslint-config-prettier": "^6.10.0",
"prettier": "^1.19.1",
"object.assign": "^4.1.0",
"object.entries": "^1.1.1"
}

View File

@@ -15,9 +15,12 @@ module.exports = {
// enforce that class methods use "this"
// https://eslint.org/docs/rules/class-methods-use-this
'class-methods-use-this': ['error', {
exceptMethods: [],
}],
'class-methods-use-this': [
'error',
{
exceptMethods: [],
},
],
// require return statements to either always or never specify values
'consistent-return': 'error',
@@ -80,13 +83,12 @@ module.exports = {
// disallow empty functions, except for standalone funcs/arrows
// https://eslint.org/docs/rules/no-empty-function
'no-empty-function': ['error', {
allow: [
'arrowFunctions',
'functions',
'methods',
]
}],
'no-empty-function': [
'error',
{
allow: ['arrowFunctions', 'functions', 'methods'],
},
],
// disallow empty destructuring patterns
// https://eslint.org/docs/rules/no-empty-pattern
@@ -122,12 +124,15 @@ module.exports = {
// disallow implicit type conversions
// https://eslint.org/docs/rules/no-implicit-coercion
'no-implicit-coercion': ['off', {
boolean: false,
number: true,
string: true,
allow: [],
}],
'no-implicit-coercion': [
'off',
{
boolean: false,
number: true,
string: true,
allow: [],
},
],
// disallow var and named functions in global scope
// https://eslint.org/docs/rules/no-implicit-globals
@@ -153,17 +158,23 @@ module.exports = {
// disallow magic numbers
// https://eslint.org/docs/rules/no-magic-numbers
'no-magic-numbers': ['off', {
ignore: [],
ignoreArrayIndexes: true,
enforceConst: true,
detectObjects: false,
}],
'no-magic-numbers': [
'off',
{
ignore: [],
ignoreArrayIndexes: true,
enforceConst: true,
detectObjects: false,
},
],
// disallow use of multiple spaces
'no-multi-spaces': ['error', {
ignoreEOLComments: false,
}],
'no-multi-spaces': [
'error',
{
ignoreEOLComments: false,
},
],
// disallow use of multiline strings
'no-multi-str': 'error',
@@ -187,21 +198,24 @@ module.exports = {
// disallow reassignment of function parameters
// disallow parameter object manipulation except for specific exclusions
// rule: https://eslint.org/docs/rules/no-param-reassign.html
'no-param-reassign': ['error', {
props: true,
ignorePropertyModificationsFor: [
'acc', // for reduce accumulators
'accumulator', // for reduce accumulators
'e', // for e.returnvalue
'ctx', // for Koa routing
'req', // for Express requests
'request', // for Express requests
'res', // for Express responses
'response', // for Express responses
'$scope', // for Angular 1 scopes
'staticContext', // for ReactRouter context
]
}],
'no-param-reassign': [
'error',
{
props: true,
ignorePropertyModificationsFor: [
'acc', // for reduce accumulators
'accumulator', // for reduce accumulators
'e', // for e.returnvalue
'ctx', // for Koa routing
'req', // for Express requests
'request', // for Express requests
'res', // for Express responses
'response', // for Express responses
'$scope', // for Angular 1 scopes
'staticContext', // for ReactRouter context
],
},
],
// disallow usage of __proto__ property
'no-proto': 'error',
@@ -211,45 +225,57 @@ module.exports = {
// disallow certain object properties
// https://eslint.org/docs/rules/no-restricted-properties
'no-restricted-properties': ['error', {
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
}, {
object: 'global',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
}, {
object: 'self',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
}, {
object: 'window',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
}, {
object: 'global',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
}, {
object: 'self',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
}, {
object: 'window',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
}, {
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
}, {
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
}, {
object: 'Math',
property: 'pow',
message: 'Use the exponentiation operator (**) instead.',
}],
'no-restricted-properties': [
'error',
{
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
},
{
object: 'global',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'self',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'window',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'global',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
object: 'self',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
object: 'window',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
},
{
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
},
{
object: 'Math',
property: 'pow',
message: 'Use the exponentiation operator (**) instead.',
},
],
// disallow use of assignment in return statement
'no-return-assign': ['error', 'always'],
@@ -262,9 +288,12 @@ module.exports = {
// disallow self assignment
// https://eslint.org/docs/rules/no-self-assign
'no-self-assign': ['error', {
props: true,
}],
'no-self-assign': [
'error',
{
props: true,
},
],
// disallow comparisons where both sides are exactly the same
'no-self-compare': 'error',
@@ -280,11 +309,14 @@ module.exports = {
'no-unmodified-loop-condition': 'off',
// disallow usage of expressions in statement position
'no-unused-expressions': ['error', {
allowShortCircuit: false,
allowTernary: false,
allowTaggedTemplates: false,
}],
'no-unused-expressions': [
'error',
{
allowShortCircuit: false,
allowTernary: false,
allowTaggedTemplates: false,
},
],
// disallow unused labels
// https://eslint.org/docs/rules/no-unused-labels
@@ -350,6 +382,6 @@ module.exports = {
'wrap-iife': ['error', 'outside', { functionPrototypeMethods: false }],
// require or disallow Yoda conditions
yoda: 'error'
}
yoda: 'error',
},
};

View File

@@ -64,13 +64,17 @@ module.exports = {
// disallow unnecessary parentheses
// https://eslint.org/docs/rules/no-extra-parens
'no-extra-parens': ['off', 'all', {
conditionalAssign: true,
nestedBinaryExpressions: false,
returnAssign: false,
ignoreJSX: 'all', // delegate to eslint-plugin-react
enforceForArrowConditionals: false,
}],
'no-extra-parens': [
'off',
'all',
{
conditionalAssign: true,
nestedBinaryExpressions: false,
returnAssign: false,
ignoreJSX: 'all', // delegate to eslint-plugin-react
enforceForArrowConditionals: false,
},
],
// disallow unnecessary semicolons
'no-extra-semi': 'error',
@@ -150,5 +154,5 @@ module.exports = {
// ensure that the results of typeof are compared against a valid string
// https://eslint.org/docs/rules/valid-typeof
'valid-typeof': ['error', { requireStringLiterals: true }],
}
},
};

View File

@@ -1,23 +1,27 @@
module.exports = {
env: {
es6: true
es6: true,
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
generators: false,
objectLiteralDuplicateProperties: false
}
objectLiteralDuplicateProperties: false,
},
},
rules: {
// enforces no braces where they can be omitted
// https://eslint.org/docs/rules/arrow-body-style
// TODO: enable requireReturnForObjectLiteral?
'arrow-body-style': ['error', 'as-needed', {
requireReturnForObjectLiteral: false,
}],
'arrow-body-style': [
'error',
'as-needed',
{
requireReturnForObjectLiteral: false,
},
],
// require parens in arrow function arguments
// https://eslint.org/docs/rules/arrow-parens
@@ -40,9 +44,12 @@ module.exports = {
// disallow arrow functions where they could be confused with comparisons
// https://eslint.org/docs/rules/no-confusing-arrow
'no-confusing-arrow': ['error', {
allowParens: true,
}],
'no-confusing-arrow': [
'error',
{
allowParens: true,
},
],
// disallow modifying variables that are declared using const
'no-const-assign': 'error',
@@ -62,10 +69,13 @@ module.exports = {
// disallow specific imports
// https://eslint.org/docs/rules/no-restricted-imports
'no-restricted-imports': ['off', {
paths: [],
patterns: []
}],
'no-restricted-imports': [
'off',
{
paths: [],
patterns: [],
},
],
// disallow to use this/super before super() calling in constructors.
// https://eslint.org/docs/rules/no-this-before-super
@@ -81,48 +91,65 @@ module.exports = {
// disallow renaming import, export, and destructured assignments to the same name
// https://eslint.org/docs/rules/no-useless-rename
'no-useless-rename': ['error', {
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false,
}],
'no-useless-rename': [
'error',
{
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false,
},
],
// require let or const instead of var
'no-var': 'error',
// require method and property shorthand syntax for object literals
// https://eslint.org/docs/rules/object-shorthand
'object-shorthand': ['error', 'always', {
ignoreConstructors: false,
avoidQuotes: true,
}],
'object-shorthand': [
'error',
'always',
{
ignoreConstructors: false,
avoidQuotes: true,
},
],
// suggest using arrow functions as callbacks
'prefer-arrow-callback': ['error', {
allowNamedFunctions: false,
allowUnboundThis: true,
}],
'prefer-arrow-callback': [
'error',
{
allowNamedFunctions: false,
allowUnboundThis: true,
},
],
// suggest using of const declaration for variables that are never modified after declared
'prefer-const': ['error', {
destructuring: 'any',
ignoreReadBeforeAssign: true,
}],
'prefer-const': [
'error',
{
destructuring: 'any',
ignoreReadBeforeAssign: true,
},
],
// Prefer destructuring from arrays and objects
// https://eslint.org/docs/rules/prefer-destructuring
'prefer-destructuring': ['error', {
VariableDeclarator: {
array: false,
object: true,
'prefer-destructuring': [
'error',
{
VariableDeclarator: {
array: false,
object: true,
},
AssignmentExpression: {
array: true,
object: false,
},
},
AssignmentExpression: {
array: true,
object: false,
{
enforceForRenamedProperties: false,
},
}, {
enforceForRenamedProperties: false,
}],
],
// disallow parseInt() in favor of binary, octal, and hexadecimal literals
// https://eslint.org/docs/rules/prefer-numeric-literals
@@ -154,12 +181,15 @@ module.exports = {
// import sorting
// https://eslint.org/docs/rules/sort-imports
'sort-imports': ['off', {
ignoreCase: false,
ignoreDeclarationSort: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
}],
'sort-imports': [
'off',
{
ignoreCase: false,
ignoreDeclarationSort: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
},
],
// require a Symbol description
// https://eslint.org/docs/rules/symbol-description
@@ -171,6 +201,6 @@ module.exports = {
// enforce spacing around the * in yield* expressions
// https://eslint.org/docs/rules/yield-star-spacing
'yield-star-spacing': ['error', 'after']
}
'yield-star-spacing': ['error', 'after'],
},
};

View File

@@ -1,32 +1,22 @@
module.exports = {
env: {
es6: true
es6: true,
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
sourceType: 'module',
},
plugins: [
'import'
],
plugins: ['import'],
settings: {
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.json']
}
extensions: ['.mjs', '.js', '.json'],
},
},
'import/extensions': [
'.js',
'.mjs',
'.jsx',
],
'import/core-modules': [
],
'import/ignore': [
'node_modules',
'\\.(coffee|scss|css|less|hbs|svg|json)$',
],
'import/extensions': ['.js', '.mjs', '.jsx'],
'import/core-modules': [],
'import/ignore': ['node_modules', '\\.(coffee|scss|css|less|hbs|svg|json)$'],
},
rules: {
@@ -68,32 +58,35 @@ module.exports = {
// Forbid the use of extraneous packages
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
// paths are treated both as absolute paths, and relative to process.cwd()
'import/no-extraneous-dependencies': ['error', {
devDependencies: [
'test/**', // tape, common npm pattern
'tests/**', // also common npm pattern
'spec/**', // mocha, rspec-like pattern
'**/__tests__/**', // jest pattern
'**/__mocks__/**', // jest pattern
'test.{js,jsx}', // repos with a single test file
'test-*.{js,jsx}', // repos with multiple top-level test files
'**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test
'**/jest.config.js', // jest config
'**/jest.setup.js', // jest setup
'**/vue.config.js', // vue-cli config
'**/webpack.config.js', // webpack config
'**/webpack.config.*.js', // webpack config
'**/rollup.config.js', // rollup config
'**/rollup.config.*.js', // rollup config
'**/gulpfile.js', // gulp config
'**/gulpfile.*.js', // gulp config
'**/Gruntfile{,.js}', // grunt config
'**/protractor.conf.js', // protractor config
'**/protractor.conf.*.js', // protractor config
'**/karma.conf.js' // karma config
],
optionalDependencies: false,
}],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'test/**', // tape, common npm pattern
'tests/**', // also common npm pattern
'spec/**', // mocha, rspec-like pattern
'**/__tests__/**', // jest pattern
'**/__mocks__/**', // jest pattern
'test.{js,jsx}', // repos with a single test file
'test-*.{js,jsx}', // repos with multiple top-level test files
'**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test
'**/jest.config.js', // jest config
'**/jest.setup.js', // jest setup
'**/vue.config.js', // vue-cli config
'**/webpack.config.js', // webpack config
'**/webpack.config.*.js', // webpack config
'**/rollup.config.js', // rollup config
'**/rollup.config.*.js', // rollup config
'**/gulpfile.js', // gulp config
'**/gulpfile.*.js', // gulp config
'**/Gruntfile{,.js}', // grunt config
'**/protractor.conf.js', // protractor config
'**/protractor.conf.*.js', // protractor config
'**/karma.conf.js', // karma config
],
optionalDependencies: false,
},
],
// Forbid mutable exports
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
@@ -136,11 +129,15 @@ module.exports = {
// Ensure consistent use of file extension within the import path
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
'import/extensions': ['error', 'ignorePackages', {
js: 'never',
mjs: 'never',
jsx: 'never',
}],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
mjs: 'never',
jsx: 'never',
},
],
// ensure absolute imports are above relative imports and that unassigned imports are ignored
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
@@ -173,9 +170,12 @@ module.exports = {
// prevent importing the submodules of other modules
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-internal-modules.md
'import/no-internal-modules': ['off', {
allow: [],
}],
'import/no-internal-modules': [
'off',
{
allow: [],
},
],
// Warn if a module could be mistakenly parsed as a script by a consumer
// leveraging Unambiguous JavaScript Grammar
@@ -199,14 +199,17 @@ module.exports = {
// Reports if a module's default export is unnamed
// https://github.com/benmosher/eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
'import/no-anonymous-default-export': ['off', {
allowArray: false,
allowArrowFunction: false,
allowAnonymousClass: false,
allowAnonymousFunction: false,
allowLiteral: false,
allowObject: false,
}],
'import/no-anonymous-default-export': [
'off',
{
allowArray: false,
allowArrowFunction: false,
allowAnonymousClass: false,
allowAnonymousFunction: false,
allowLiteral: false,
allowObject: false,
},
],
// This rule enforces that all exports are declared at the bottom of the file.
// https://github.com/benmosher/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
@@ -241,10 +244,13 @@ module.exports = {
// dynamic imports require a leading comment with a webpackChunkName
// https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md
'import/dynamic-import-chunkname': ['off', {
importFunctions: [],
webpackChunknameFormat: '[0-9a-zA-Z-_/.]+',
}],
'import/dynamic-import-chunkname': [
'off',
{
importFunctions: [],
webpackChunknameFormat: '[0-9a-zA-Z-_/.]+',
},
],
// Use this rule to prevent imports to folders in relative parent paths.
// https://github.com/benmosher/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
@@ -253,10 +259,13 @@ module.exports = {
// Reports modules without any exports, or with unused exports
// https://github.com/benmosher/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
// TODO: enable, semver-major
'import/no-unused-modules': ['off', {
ignoreExports: [],
missingExports: true,
unusedExports: true,
}],
'import/no-unused-modules': [
'off',
{
ignoreExports: [],
missingExports: true,
unusedExports: true,
},
],
},
};

View File

@@ -1,6 +1,6 @@
module.exports = {
env: {
node: true
node: true,
},
rules: {
@@ -39,5 +39,5 @@ module.exports = {
// disallow use of synchronous methods (off by default)
'no-sync': 'off',
}
},
};

View File

@@ -0,0 +1,26 @@
module.exports = {
extends: ['prettier'],
plugins: ['prettier'],
rules: {
// Prettier Rule + Prettier config overrides
'prettier/prettier': [
'error',
{
arrowParens: 'always',
bracketSpacing: true,
jsxBracketSameLine: false,
printWidth: 100,
proseWrap: 'preserve',
requirePragma: false,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
useTabs: false,
},
{
usePrettierrc: false,
},
],
},
};

View File

@@ -1,6 +1,6 @@
module.exports = {
rules: {
// babel inserts `'use strict';` for us
strict: ['error', 'never']
}
strict: ['error', 'never'],
},
};

View File

@@ -25,47 +25,58 @@ module.exports = {
// enforce or disallow capitalization of the first letter of a comment
// https://eslint.org/docs/rules/capitalized-comments
'capitalized-comments': ['off', 'never', {
line: {
ignorePattern: '.*',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
'capitalized-comments': [
'off',
'never',
{
line: {
ignorePattern: '.*',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
block: {
ignorePattern: '.*',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
},
block: {
ignorePattern: '.*',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
}],
],
// require trailing commas in multiline object literals
'comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
}],
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
},
],
// enforce spacing before and after comma
'comma-spacing': ['error', { before: false, after: true }],
// enforce one true comma style
'comma-style': ['error', 'last', {
exceptions: {
ArrayExpression: false,
ArrayPattern: false,
ArrowFunctionExpression: false,
CallExpression: false,
FunctionDeclaration: false,
FunctionExpression: false,
ImportDeclaration: false,
ObjectExpression: false,
ObjectPattern: false,
VariableDeclaration: false,
NewExpression: false,
}
}],
'comma-style': [
'error',
'last',
{
exceptions: {
ArrayExpression: false,
ArrayPattern: false,
ArrowFunctionExpression: false,
CallExpression: false,
FunctionDeclaration: false,
FunctionExpression: false,
ImportDeclaration: false,
ObjectExpression: false,
ObjectPattern: false,
VariableDeclaration: false,
NewExpression: false,
},
},
],
// disallow padding inside computed properties
'computed-property-spacing': ['error', 'never'],
@@ -87,10 +98,14 @@ module.exports = {
// requires function names to match the name of the variable or property to which they are
// assigned
// https://eslint.org/docs/rules/func-name-matching
'func-name-matching': ['off', 'always', {
includeCommonJSModuleExports: false,
considerPropertyDescriptor: true,
}],
'func-name-matching': [
'off',
'always',
{
includeCommonJSModuleExports: false,
considerPropertyDescriptor: true,
},
],
// require function expressions to have a name
// https://eslint.org/docs/rules/func-names
@@ -122,30 +137,51 @@ module.exports = {
// this option sets a specific tab width for your code
// https://eslint.org/docs/rules/indent
indent: ['error', 2, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
// MemberExpression: null,
FunctionDeclaration: {
parameters: 1,
body: 1
indent: [
'error',
2,
{
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
// MemberExpression: null,
FunctionDeclaration: {
parameters: 1,
body: 1,
},
FunctionExpression: {
parameters: 1,
body: 1,
},
CallExpression: {
arguments: 1,
},
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
ignoredNodes: [
'JSXElement',
'JSXElement > *',
'JSXAttribute',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXSpreadAttribute',
'JSXExpressionContainer',
'JSXOpeningElement',
'JSXClosingElement',
'JSXFragment',
'JSXOpeningFragment',
'JSXClosingFragment',
'JSXText',
'JSXEmptyExpression',
'JSXSpreadChild',
],
ignoreComments: false,
},
FunctionExpression: {
parameters: 1,
body: 1
},
CallExpression: {
arguments: 1
},
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
ignoredNodes: ['JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXFragment', 'JSXOpeningFragment', 'JSXClosingFragment', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild'],
ignoreComments: false
}],
],
// specify whether double or single quotes should be used in JSX attributes
// https://eslint.org/docs/rules/jsx-quotes
@@ -155,24 +191,30 @@ module.exports = {
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
// require a space before & after certain keywords
'keyword-spacing': ['error', {
before: true,
after: true,
overrides: {
return: { after: true },
throw: { after: true },
case: { after: true }
}
}],
'keyword-spacing': [
'error',
{
before: true,
after: true,
overrides: {
return: { after: true },
throw: { after: true },
case: { after: true },
},
},
],
// enforce position of line comments
// https://eslint.org/docs/rules/line-comment-position
// TODO: enable?
'line-comment-position': ['off', {
position: 'above',
ignorePattern: '',
applyDefaultPatterns: true,
}],
'line-comment-position': [
'off',
{
position: 'above',
ignorePattern: '',
applyDefaultPatterns: true,
},
],
// disallow mixed 'LF' and 'CRLF' as linebreaks
// https://eslint.org/docs/rules/linebreak-style
@@ -187,40 +229,54 @@ module.exports = {
// require or disallow newlines around directives
// https://eslint.org/docs/rules/lines-around-directive
'lines-around-directive': ['error', {
before: 'always',
after: 'always',
}],
'lines-around-directive': [
'error',
{
before: 'always',
after: 'always',
},
],
// specify the maximum depth that blocks can be nested
'max-depth': ['off', 4],
// specify the maximum length of a line in your program
// https://eslint.org/docs/rules/max-len
'max-len': ['error', 100, 2, {
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
'max-len': [
'error',
100,
2,
{
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
// specify the max number of lines in a file
// https://eslint.org/docs/rules/max-lines
'max-lines': ['off', {
max: 300,
skipBlankLines: true,
skipComments: true
}],
'max-lines': [
'off',
{
max: 300,
skipBlankLines: true,
skipComments: true,
},
],
// enforce a maximum function length
// https://eslint.org/docs/rules/max-lines-per-function
'max-lines-per-function': ['off', {
max: 50,
skipBlankLines: true,
skipComments: true,
IIFEs: true,
}],
'max-lines-per-function': [
'off',
{
max: 50,
skipBlankLines: true,
skipComments: true,
IIFEs: true,
},
],
// specify the maximum depth callbacks can be nested
'max-nested-callbacks': 'off',
@@ -245,12 +301,15 @@ module.exports = {
'multiline-ternary': ['off', 'never'],
// require a capital letter for constructors
'new-cap': ['error', {
newIsCap: true,
newIsCapExceptions: [],
capIsNew: false,
capIsNewExceptions: ['Immutable.Map', 'Immutable.Set', 'Immutable.List'],
}],
'new-cap': [
'error',
{
newIsCap: true,
newIsCapExceptions: [],
capIsNew: false,
capIsNewExceptions: ['Immutable.Map', 'Immutable.Set', 'Immutable.List'],
},
],
// disallow the omission of parentheses when invoking a constructor with no arguments
// https://eslint.org/docs/rules/new-parens
@@ -287,22 +346,25 @@ module.exports = {
// disallow un-paren'd mixes of different operators
// https://eslint.org/docs/rules/no-mixed-operators
'no-mixed-operators': ['error', {
// the list of arthmetic groups disallows mixing `%` and `**`
// with other arithmetic operators.
groups: [
['%', '**'],
['%', '+'],
['%', '-'],
['%', '*'],
['%', '/'],
['/', '*'],
['&', '|', '<<', '>>', '>>>'],
['==', '!=', '===', '!=='],
['&&', '||'],
],
allowSamePrecedence: false
}],
'no-mixed-operators': [
'error',
{
// the list of arthmetic groups disallows mixing `%` and `**`
// with other arithmetic operators.
groups: [
['%', '**'],
['%', '+'],
['%', '-'],
['%', '*'],
['%', '/'],
['/', '*'],
['&', '|', '<<', '>>', '>>>'],
['==', '!=', '===', '!=='],
['&&', '||'],
],
allowSamePrecedence: false,
},
],
// disallow mixed spaces and tabs for indentation
'no-mixed-spaces-and-tabs': 'error',
@@ -335,19 +397,23 @@ module.exports = {
'error',
{
selector: 'ForInStatement',
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'ForOfStatement',
message: 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
message:
'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
},
{
selector: 'LabeledStatement',
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
@@ -361,19 +427,25 @@ module.exports = {
'no-ternary': 'off',
// disallow trailing whitespace at the end of lines
'no-trailing-spaces': ['error', {
skipBlankLines: false,
ignoreComments: false,
}],
'no-trailing-spaces': [
'error',
{
skipBlankLines: false,
ignoreComments: false,
},
],
// disallow dangling underscores in identifiers
// https://eslint.org/docs/rules/no-underscore-dangle
'no-underscore-dangle': ['error', {
allow: [],
allowAfterThis: false,
allowAfterSuper: false,
enforceInMethodNames: true,
}],
'no-underscore-dangle': [
'error',
{
allow: [],
allowAfterThis: false,
allowAfterSuper: false,
enforceInMethodNames: true,
},
],
// disallow the use of Boolean literals in conditional expressions
// also, prefer `a || b` over `a ? a : b`
@@ -393,18 +465,24 @@ module.exports = {
// enforce line breaks between braces
// https://eslint.org/docs/rules/object-curly-newline
'object-curly-newline': ['error', {
ObjectExpression: { minProperties: 4, multiline: true, consistent: true },
ObjectPattern: { minProperties: 4, multiline: true, consistent: true },
ImportDeclaration: { minProperties: 4, multiline: true, consistent: true },
ExportDeclaration: { minProperties: 4, multiline: true, consistent: true },
}],
'object-curly-newline': [
'error',
{
ObjectExpression: { minProperties: 4, multiline: true, consistent: true },
ObjectPattern: { minProperties: 4, multiline: true, consistent: true },
ImportDeclaration: { minProperties: 4, multiline: true, consistent: true },
ExportDeclaration: { minProperties: 4, multiline: true, consistent: true },
},
],
// enforce "same line" or "multiple line" on object properties.
// https://eslint.org/docs/rules/object-property-newline
'object-property-newline': ['error', {
allowAllPropertiesOnSameLine: true,
}],
'object-property-newline': [
'error',
{
allowAllPropertiesOnSameLine: true,
},
],
// allow just one var statement per function
'one-var': ['error', 'never'],
@@ -422,13 +500,17 @@ module.exports = {
'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }],
// disallow padding within blocks
'padded-blocks': ['error', {
blocks: 'never',
classes: 'never',
switches: 'never',
}, {
allowSingleLineBlocks: true,
}],
'padded-blocks': [
'error',
{
blocks: 'never',
classes: 'never',
switches: 'never',
},
{
allowSingleLineBlocks: true,
},
],
// Require or disallow padding lines between statements
// https://eslint.org/docs/rules/padding-line-between-statements
@@ -475,11 +557,14 @@ module.exports = {
// require or disallow space before function opening parenthesis
// https://eslint.org/docs/rules/space-before-function-paren
'space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always'
}],
'space-before-function-paren': [
'error',
{
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
},
],
// require or disallow spaces inside parentheses
'space-in-parens': ['error', 'never'],
@@ -489,26 +574,32 @@ module.exports = {
// Require or disallow spaces before/after unary operators
// https://eslint.org/docs/rules/space-unary-ops
'space-unary-ops': ['error', {
words: true,
nonwords: false,
overrides: {
'space-unary-ops': [
'error',
{
words: true,
nonwords: false,
overrides: {},
},
}],
],
// require or disallow a space immediately following the // or /* in a comment
// https://eslint.org/docs/rules/spaced-comment
'spaced-comment': ['error', 'always', {
line: {
exceptions: ['-', '+'],
markers: ['=', '!'], // space here to support sprockets directives
'spaced-comment': [
'error',
'always',
{
line: {
exceptions: ['-', '+'],
markers: ['=', '!'], // space here to support sprockets directives
},
block: {
exceptions: ['-', '+'],
markers: ['=', '!', ':', '::'], // space here to support sprockets directives and flow comment types
balanced: true,
},
},
block: {
exceptions: ['-', '+'],
markers: ['=', '!', ':', '::'], // space here to support sprockets directives and flow comment types
balanced: true,
}
}],
],
// Enforce spacing around colons of switch statements
// https://eslint.org/docs/rules/switch-colon-spacing
@@ -523,6 +614,6 @@ module.exports = {
'unicode-bom': ['error', 'never'],
// require regex literals to be wrapped in parentheses
'wrap-regex': 'off'
}
'wrap-regex': 'off',
},
};

View File

@@ -40,5 +40,5 @@ module.exports = {
// disallow use of variables before they are defined
'no-use-before-define': ['error', { functions: true, classes: true, variables: true }],
}
},
};

View File

@@ -11,22 +11,26 @@ fs.readdirSync(path.join(__dirname, '../rules')).forEach((name) => {
files[name] = require(`../rules/${name}`); // eslint-disable-line global-require
});
Object.keys(files).forEach((
name, // trailing function comma is to test parsing
) => {
const config = files[name];
Object.keys(files).forEach(
(
name, // trailing function comma is to test parsing
) => {
const config = files[name];
test(`${name}: does not reference react`, (t) => {
t.plan(2);
test(`${name}: does not reference react`, (t) => {
t.plan(2);
// scan plugins for react and fail if it is found
const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins')
&& config.plugins.indexOf('react') !== -1;
t.notOk(hasReactPlugin, 'there is no react plugin');
// scan plugins for react and fail if it is found
const hasReactPlugin =
Object.prototype.hasOwnProperty.call(config, 'plugins') &&
config.plugins.indexOf('react') !== -1;
t.notOk(hasReactPlugin, 'there is no react plugin');
// scan rules for react/ and fail if any exist
const reactRuleIds = Object.keys(config.rules)
.filter((ruleId) => ruleId.indexOf('react/') === 0);
t.deepEquals(reactRuleIds, [], 'there are no react/ rules');
});
});
// scan rules for react/ and fail if any exist
const reactRuleIds = Object.keys(config.rules).filter(
(ruleId) => ruleId.indexOf('react/') === 0,
);
t.deepEquals(reactRuleIds, [], 'there are no react/ rules');
});
},
);

View File

@@ -40,52 +40,55 @@ function onlyErrorOnRules(rulesToError, config) {
return errorsOnly;
}
module.exports = onlyErrorOnRules([
'array-bracket-newline',
'array-bracket-spacing',
'array-element-newline',
'arrow-spacing',
'block-spacing',
'comma-spacing',
'computed-property-spacing',
'dot-location',
'eol-last',
'func-call-spacing',
'function-paren-newline',
'generator-star-spacing',
'implicit-arrow-linebreak',
'indent',
'key-spacing',
'keyword-spacing',
'line-comment-position',
'linebreak-style',
'multiline-ternary',
'newline-per-chained-call',
'no-irregular-whitespace',
'no-mixed-spaces-and-tabs',
'no-multi-spaces',
'no-regex-spaces',
'no-spaced-func',
'no-trailing-spaces',
'no-whitespace-before-property',
'nonblock-statement-body-position',
'object-curly-newline',
'object-curly-spacing',
'object-property-newline',
'one-var-declaration-per-line',
'operator-linebreak',
'padded-blocks',
'padding-line-between-statements',
'rest-spread-spacing',
'semi-spacing',
'semi-style',
'space-before-blocks',
'space-before-function-paren',
'space-in-parens',
'space-infix-ops',
'space-unary-ops',
'spaced-comment',
'switch-colon-spacing',
'template-tag-spacing',
'import/newline-after-import',
], baseConfig);
module.exports = onlyErrorOnRules(
[
'array-bracket-newline',
'array-bracket-spacing',
'array-element-newline',
'arrow-spacing',
'block-spacing',
'comma-spacing',
'computed-property-spacing',
'dot-location',
'eol-last',
'func-call-spacing',
'function-paren-newline',
'generator-star-spacing',
'implicit-arrow-linebreak',
'indent',
'key-spacing',
'keyword-spacing',
'line-comment-position',
'linebreak-style',
'multiline-ternary',
'newline-per-chained-call',
'no-irregular-whitespace',
'no-mixed-spaces-and-tabs',
'no-multi-spaces',
'no-regex-spaces',
'no-spaced-func',
'no-trailing-spaces',
'no-whitespace-before-property',
'nonblock-statement-body-position',
'object-curly-newline',
'object-curly-spacing',
'object-property-newline',
'one-var-declaration-per-line',
'operator-linebreak',
'padded-blocks',
'padding-line-between-statements',
'rest-spread-spacing',
'semi-spacing',
'semi-style',
'space-before-blocks',
'space-before-function-paren',
'space-in-parens',
'space-infix-ops',
'space-unary-ops',
'spaced-comment',
'switch-colon-spacing',
'template-tag-spacing',
'import/newline-after-import',
],
baseConfig,
);