Skip to content

Commit aa53fbd

Browse files
authored
feat(lint): add Airbnb and Unicorn eslint packages
Add eslint plugin packages with recommended rules to be fixed in separate PRs.
1 parent 2722e1b commit aa53fbd

File tree

10 files changed

+599
-94
lines changed

10 files changed

+599
-94
lines changed

.eslintrc.js

Lines changed: 141 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module.exports = {
44
es6: true,
55
},
66
extends: [
7+
'airbnb-base',
8+
'plugin:unicorn/recommended',
79
],
810
parserOptions: {
911
ecmaVersion: '2020',
@@ -17,43 +19,47 @@ module.exports = {
1719
'/test/helpers',
1820
],
1921
rules: {
20-
indent: ['error', 4, { SwitchCase: 1 }],
21-
'keyword-spacing': ['error'],
22-
'space-in-parens': ['error'],
23-
'comma-spacing': ['error'],
24-
'comma-style': ['error', 'last', {
25-
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-v19.0.4/packages/eslint-config-airbnb-base/rules/style.js#L54
22+
'class-methods-use-this': 'off',
23+
'comma-dangle': ['error', {
24+
arrays: 'always-multiline',
25+
objects: 'always-multiline',
26+
functions: 'never',
27+
imports: 'always-multiline',
28+
exports: 'always-multiline',
29+
}],
30+
'consistent-return': 'off',
31+
curly: ['error', 'all'],
32+
'default-case': 'off',
33+
'func-names': 'off',
34+
'import/no-unresolved': 'off',
35+
'import/prefer-default-export': 'off',
36+
indent: ['error', 4, {
37+
SwitchCase: 1,
38+
}],
39+
'max-len': 'off',
40+
'no-console': 'off',
41+
'no-continue': 'off',
42+
'no-lonely-if': 'off',
43+
'no-multi-spaces': ['error', {
2644
exceptions: {
27-
ArrayExpression: false,
28-
ArrayPattern: false,
29-
ArrowFunctionExpression: false,
30-
CallExpression: false,
31-
FunctionDeclaration: false,
32-
FunctionExpression: false,
33-
ImportDeclaration: false,
34-
ObjectExpression: false,
35-
ObjectPattern: false,
36-
VariableDeclaration: false,
37-
NewExpression: false,
45+
Property: true,
46+
VariableDeclarator: true,
3847
},
3948
}],
40-
'space-before-function-paren': ['error', {
41-
named: 'never',
42-
anonymous: 'always',
43-
asyncArrow: 'always',
44-
}],
45-
'space-infix-ops': ['error'],
46-
'array-bracket-spacing': ['error', 'never'],
47-
'object-curly-spacing': ['error', 'always'],
48-
'computed-property-spacing': ['error', 'never'],
49-
'space-before-blocks': ['error'],
50-
'one-var-declaration-per-line': ['error', 'always'],
51-
'function-paren-newline': ['error', 'multiline-arguments'],
49+
'no-nested-ternary': 'off',
50+
'no-param-reassign': 'off',
51+
'no-plusplus': 'off',
52+
'no-restricted-syntax': 'off',
53+
'no-underscore-dangle': 'off',
54+
'no-unused-vars': 'off',
55+
'object-shorthand': ['error', 'never'],
5256
'padding-line-between-statements': ['error', {
5357
blankLine: 'always',
5458
prev: '*',
5559
next: ['continue', 'break', 'export', 'return', 'throw'],
5660
}],
61+
'prefer-destructuring': 'off',
62+
'prefer-template': 'off',
5763
'spaced-comment': ['error', 'always', {
5864
line: {
5965
markers: ['/'],
@@ -65,47 +71,112 @@ module.exports = {
6571
balanced: true,
6672
},
6773
}],
68-
'padded-blocks': ['error', 'never'],
69-
'no-multiple-empty-lines': ['error', {
70-
max: 1,
71-
maxBOF: 0,
72-
maxEOF: 0,
73-
}],
74-
'no-multi-spaces': ['error', {
75-
exceptions: {
76-
Property: true,
77-
VariableDeclarator: true,
78-
},
79-
}],
80-
'brace-style': ['error'],
81-
curly: ['error'],
82-
'object-shorthand': ['error', 'never'],
83-
'object-curly-newline': ['error', {
84-
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-v19.0.4/packages/eslint-config-airbnb-base/rules/style.js#L395
85-
ObjectExpression: { minProperties: 4, multiline: true, consistent: true },
86-
ObjectPattern: { minProperties: 4, multiline: true, consistent: true },
87-
ImportDeclaration: { minProperties: 4, multiline: true, consistent: true },
88-
ExportDeclaration: { minProperties: 4, multiline: true, consistent: true },
89-
}],
90-
'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }],
91-
'dot-notation': ['error', { allowKeywords: true }],
92-
'arrow-parens': ['error'],
93-
quotes: ['error', 'single', { avoidEscape: true }],
94-
'quote-props': ['error', 'as-needed', {
95-
keywords: false,
96-
numbers: false,
97-
}],
98-
'comma-dangle': ['error', {
99-
arrays: 'always-multiline',
100-
objects: 'always-multiline',
101-
functions: 'never',
102-
imports: 'always-multiline',
103-
exports: 'always-multiline',
104-
}],
105-
semi: ['error'],
106-
'no-extra-semi': ['error'],
107-
'no-trailing-spaces': ['error'],
108-
'array-callback-return': ['error', { allowImplicit: true }],
74+
strict: 'off',
75+
'unicorn/catch-error-name': 'off',
76+
'unicorn/no-array-callback-reference': 'off',
77+
'unicorn/no-lonely-if': 'off',
78+
'unicorn/no-negated-condition': 'off',
79+
'unicorn/no-null': 'off',
80+
'unicorn/no-this-assignment': 'off',
81+
'unicorn/numeric-separators-style': 'off',
82+
'unicorn/prefer-array-some': 'off', // https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2007
83+
'unicorn/prefer-module': 'off',
84+
'unicorn/prevent-abbreviations': 'off',
85+
'unicorn/switch-case-braces': ['error', 'avoid'],
86+
'wrap-iife': ['error', 'inside'],
87+
88+
// TODO rules to be removed/fixed in v2.10.0 as fixes are not compatible with IE11
89+
'guard-for-in': 'off', // refactor to "for of"
90+
'no-restricted-globals': 'off',
91+
'no-restricted-properties': 'off',
92+
'no-var': 'off', // https://github.com/fomantic/Fomantic-UI/pull/2584
93+
'one-var': 'off',
94+
'prefer-const': 'off',
95+
'prefer-exponentiation-operator': 'off',
96+
'prefer-spread': 'off',
97+
'semi-style': 'off',
98+
'unicorn/no-array-for-each': 'off',
99+
'unicorn/no-for-loop': 'off', // autofixes to "for of"
100+
'unicorn/prefer-code-point': 'off',
101+
'unicorn/prefer-includes': 'off',
102+
'unicorn/prefer-node-protocol': 'off', // needs Node 14+
103+
'unicorn/prefer-number-properties': 'off',
104+
'unicorn/prefer-optional-catch-binding': 'off',
105+
'unicorn/prefer-prototype-methods': 'off',
106+
'unicorn/prefer-reflect-apply': 'off',
107+
'unicorn/prefer-spread': 'off',
108+
'unicorn/prefer-top-level-await': 'off', // needs Node 14+
109+
'vars-on-top': 'off',
110+
111+
// TODO rules with a lot of errors to be fixed manually, fix in a separate PR
112+
eqeqeq: 'off', // about 300 errors to be fixed manually
113+
'global-require': 'off', // about 30 errors to be fixed manually
114+
'no-shadow': 'off', // about 220 errors to be fixed manually
115+
'prefer-arrow-callback': 'off', // about 350 errors (all autofixable)
116+
'prefer-rest-params': 'off', // about 180 errors to be fixed manually
117+
'unicorn/no-nested-ternary': 'off', // about 80 errors (except 14 nested ternary operators autofixable)
118+
119+
// TODO
120+
'import/extensions': 'off',
121+
'import/no-dynamic-require': 'off',
122+
'no-bitwise': 'off',
123+
'no-cond-assign': 'off',
124+
'no-else-return': 'off',
125+
'no-empty': 'off',
126+
'no-labels': 'off',
127+
'no-loop-func': 'off',
128+
'no-mixed-operators': 'off',
129+
'no-multi-assign': 'off',
130+
'no-new-func': 'off',
131+
'no-path-concat': 'off',
132+
'no-prototype-builtins': 'off',
133+
'no-return-assign': 'off',
134+
'no-self-assign': 'off',
135+
'no-shadow-restricted-names': 'off',
136+
'no-unused-expressions': 'off',
137+
'no-use-before-define': 'off',
138+
'no-useless-concat': 'off',
139+
'no-useless-escape': 'off',
140+
radix: 'off',
141+
'unicorn/better-regex': 'off',
142+
'unicorn/consistent-function-scoping': 'off',
143+
'unicorn/empty-brace-spaces': 'off',
144+
'unicorn/escape-case': 'off',
145+
'unicorn/explicit-length-check': 'off',
146+
'unicorn/new-for-builtins': 'off',
147+
'unicorn/no-hex-escape': 'off',
148+
'unicorn/no-instanceof-array': 'off',
149+
'unicorn/no-process-exit': 'off',
150+
'unicorn/no-typeof-undefined': 'off',
151+
'unicorn/no-useless-switch-case': 'off',
152+
'unicorn/no-useless-undefined': 'off',
153+
'unicorn/prefer-array-find': 'off',
154+
'unicorn/prefer-date-now': 'off',
155+
'unicorn/prefer-default-parameters': 'off',
156+
'unicorn/prefer-logical-operator-over-ternary': 'off',
157+
'unicorn/prefer-native-coercion-functions': 'off',
158+
'unicorn/prefer-negative-index': 'off',
159+
'unicorn/prefer-regexp-test': 'off',
160+
'unicorn/prefer-switch': 'off',
161+
'unicorn/prefer-ternary': 'off',
162+
163+
// TODO rare errors
164+
'arrow-body-style': 'off',
165+
'block-scoped-var': 'off',
166+
'import/no-extraneous-dependencies': 'off',
167+
'import/order': 'off',
168+
'new-cap': 'off',
169+
'newline-per-chained-call': 'off',
170+
'no-extra-boolean-cast': 'off',
171+
'no-redeclare': 'off',
172+
'no-unneeded-ternary': 'off',
173+
'no-useless-return': 'off',
174+
'operator-assignment': 'off',
175+
'unicorn/no-console-spaces': 'off',
176+
yoda: 'off',
109177
},
110178
reportUnusedDisableDirectives: true,
179+
globals: {
180+
jQuery: true,
181+
},
111182
};

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v3
1212
- uses: actions/setup-node@v3
1313
- name: Install dependencies
14-
run: yarn
14+
run: yarn && yarn add -D eslint-config-airbnb-base eslint-plugin-unicorn eslint-plugin-jest@^26.9.0 @typescript-eslint/eslint-plugin @typescript-eslint/parser typescript
1515
- name: Lint JS and CSS/LESS files
1616
run: npm run lint
1717
test:
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
node-version: [12, 14, 16, 18]
23+
node-version: [12, 14, 16, 18, latest]
2424
steps:
2525
- uses: actions/checkout@v3
2626
- name: Setup Node.js ${{ matrix.node-version }}

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
ref: develop
1919
- uses: actions/setup-node@v3
2020
with:
21-
node-version: 16
21+
node-version: 18
2222
registry-url: https://registry.npmjs.org/
2323
- name: pre-setup
2424
run: sh ./scripts/preinstall.sh

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
ref: master
1717
- uses: actions/setup-node@v3
1818
with:
19-
node-version: 14
19+
node-version: 18
2020
registry-url: https://registry.npmjs.org/
2121
- name: pre-setup
2222
run: sh ./scripts/preinstall.sh

examples/.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
globals: {
3+
jQuery: false,
4+
$: true,
5+
},
6+
};

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@actions/core": "^1.6.0",
3434
"@octokit/core": "^3.6.0",
3535
"@octokit/rest": "^16.16.0",
36-
"better-console": "1.0.1",
36+
"better-console": "^1.0.1",
3737
"browserslist": "^4.19.1",
3838
"del": "^6.1.1",
3939
"extend": "^3.0.2",
@@ -46,7 +46,7 @@
4646
"gulp-concat-css": "^3.1.0",
4747
"gulp-concat-filenames": "^1.2.0",
4848
"gulp-copy": "^4.0.0",
49-
"gulp-dedupe": "0.0.2",
49+
"gulp-dedupe": "^0.0.2",
5050
"gulp-flatten": "^0.4.0",
5151
"gulp-git": "^2.9.0",
5252
"gulp-header": "^2.0.5",
@@ -75,7 +75,8 @@
7575
"devDependencies": {
7676
"all-contributors-cli": "^6.7.0",
7777
"auto-changelog": "^2.4.0",
78-
"eslint": "^8.28.0",
78+
"eslint": "^8.29.0",
79+
"eslint-plugin-import": "^2.26.0",
7980
"node-fetch": "^2.6.0",
8081
"postcss": "^8.4.19",
8182
"postcss-less": "^6.0.0",

src/definitions/modules/calendar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@
758758
var ms1d = 864e5, // milliseconds in a day
759759
ms7d = 7 * ms1d; // milliseconds in a week
760760

761+
// eslint-disable-next-line wrap-iife
761762
return function () { // return a closure so constants get calculated only once
762763
var DC3 = Date.UTC(weekYear, weekMonth, weekDay + 3) / ms1d, // an Absolute Day Number
763764
AWN = Math.floor(DC3 / 7), // an Absolute Week Number

tasks/.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
rules: {
3+
'no-use-before-define': 'off', // TODO code should be fixed and this ignore removed
4+
},
5+
globals: {
6+
files: true,
7+
Package: true,
8+
},
9+
};

test/.eslintrc.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
extends: [
3+
'plugin:jest/recommended',
4+
],
5+
settings: {
6+
jest: {
7+
version: 29,
8+
},
9+
},
10+
rules: {
11+
'jest/no-disabled-tests': 'off',
12+
13+
// TODO rare errors
14+
'jest/no-jasmine-globals': 'off',
15+
'jest/no-test-prefixes': 'off',
16+
},
17+
globals: {
18+
jQuery: false,
19+
$: true,
20+
dump: true,
21+
HTTP: true,
22+
jasmine: true,
23+
moduleTests: true,
24+
sandbox: true,
25+
Tinytest: true,
26+
},
27+
};

0 commit comments

Comments
 (0)