Skip to content

Commit

Permalink
Add Airbnb and Unicorn linters compatible with Node 12
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 11, 2022
1 parent 2722e1b commit 91ec658
Show file tree
Hide file tree
Showing 12 changed files with 603 additions and 102 deletions.
211 changes: 141 additions & 70 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module.exports = {
es6: true,
},
extends: [
'airbnb-base',
'plugin:unicorn/recommended',
],
parserOptions: {
ecmaVersion: '2020',
Expand All @@ -17,43 +19,47 @@ module.exports = {
'/test/helpers',
],
rules: {
indent: ['error', 4, { SwitchCase: 1 }],
'keyword-spacing': ['error'],
'space-in-parens': ['error'],
'comma-spacing': ['error'],
'comma-style': ['error', 'last', {
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-v19.0.4/packages/eslint-config-airbnb-base/rules/style.js#L54
'class-methods-use-this': 'off',
'comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
functions: 'never',
imports: 'always-multiline',
exports: 'always-multiline',
}],
'consistent-return': 'off',
curly: ['error', 'all'],
'default-case': 'off',
'func-names': 'off',
'import/no-unresolved': 'off',
'import/prefer-default-export': 'off',
indent: ['error', 4, {
SwitchCase: 1,
}],
'max-len': 'off',
'no-console': 'off',
'no-continue': 'off',
'no-lonely-if': 'off',
'no-multi-spaces': ['error', {
exceptions: {
ArrayExpression: false,
ArrayPattern: false,
ArrowFunctionExpression: false,
CallExpression: false,
FunctionDeclaration: false,
FunctionExpression: false,
ImportDeclaration: false,
ObjectExpression: false,
ObjectPattern: false,
VariableDeclaration: false,
NewExpression: false,
Property: true,
VariableDeclarator: true,
},
}],
'space-before-function-paren': ['error', {
named: 'never',
anonymous: 'always',
asyncArrow: 'always',
}],
'space-infix-ops': ['error'],
'array-bracket-spacing': ['error', 'never'],
'object-curly-spacing': ['error', 'always'],
'computed-property-spacing': ['error', 'never'],
'space-before-blocks': ['error'],
'one-var-declaration-per-line': ['error', 'always'],
'function-paren-newline': ['error', 'multiline-arguments'],
'no-nested-ternary': 'off',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-restricted-syntax': 'off',
'no-underscore-dangle': 'off',
'no-unused-vars': 'off',
'object-shorthand': ['error', 'never'],
'padding-line-between-statements': ['error', {
blankLine: 'always',
prev: '*',
next: ['continue', 'break', 'export', 'return', 'throw'],
}],
'prefer-destructuring': 'off',
'prefer-template': 'off',
'spaced-comment': ['error', 'always', {
line: {
markers: ['/'],
Expand All @@ -65,47 +71,112 @@ module.exports = {
balanced: true,
},
}],
'padded-blocks': ['error', 'never'],
'no-multiple-empty-lines': ['error', {
max: 1,
maxBOF: 0,
maxEOF: 0,
}],
'no-multi-spaces': ['error', {
exceptions: {
Property: true,
VariableDeclarator: true,
},
}],
'brace-style': ['error'],
curly: ['error'],
'object-shorthand': ['error', 'never'],
'object-curly-newline': ['error', {
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-v19.0.4/packages/eslint-config-airbnb-base/rules/style.js#L395
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 },
}],
'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }],
'dot-notation': ['error', { allowKeywords: true }],
'arrow-parens': ['error'],
quotes: ['error', 'single', { avoidEscape: true }],
'quote-props': ['error', 'as-needed', {
keywords: false,
numbers: false,
}],
'comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
functions: 'never',
imports: 'always-multiline',
exports: 'always-multiline',
}],
semi: ['error'],
'no-extra-semi': ['error'],
'no-trailing-spaces': ['error'],
'array-callback-return': ['error', { allowImplicit: true }],
strict: 'off',
'unicorn/catch-error-name': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-lonely-if': 'off',
'unicorn/no-negated-condition': 'off',
'unicorn/no-null': 'off',
'unicorn/no-this-assignment': 'off',
'unicorn/numeric-separators-style': 'off',
'unicorn/prefer-array-some': 'off', // https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2007
'unicorn/prefer-module': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/switch-case-braces': ['error', 'avoid'],
'wrap-iife': ['error', 'inside'],

// TODO rules to be removed/fixed in v2.10.0 as fixes are not compatible with IE11
'guard-for-in': 'off', // refactor to "for of"
'no-restricted-globals': 'off',
'no-restricted-properties': 'off',
'no-var': 'off', // https://github.com/fomantic/Fomantic-UI/pull/2584
'one-var': 'off',
'prefer-const': 'off',
'prefer-exponentiation-operator': 'off',
'prefer-spread': 'off',
'semi-style': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/no-for-loop': 'off', // autofixes to "for of"
'unicorn/prefer-code-point': 'off',
'unicorn/prefer-includes': 'off',
'unicorn/prefer-node-protocol': 'off', // needs Node 14+
'unicorn/prefer-number-properties': 'off',
'unicorn/prefer-optional-catch-binding': 'off',
'unicorn/prefer-prototype-methods': 'off',
'unicorn/prefer-reflect-apply': 'off',
'unicorn/prefer-spread': 'off',
'unicorn/prefer-top-level-await': 'off', // needs Node 14+
'vars-on-top': 'off',

// TODO rules with a lot of errors to be fixed manually, fix in a separate PR
eqeqeq: 'off', // about 300 errors to be fixed manually
'global-require': 'off', // about 30 errors to be fixed manually
'no-shadow': 'off', // about 220 errors to be fixed manually
'prefer-arrow-callback': 'off', // about 350 errors (all autofixable)
'prefer-rest-params': 'off', // about 180 errors to be fixed manually
'unicorn/no-nested-ternary': 'off', // about 80 errors (except 14 nested ternary operators autofixable)

// TODO
'import/extensions': 'off',
'import/no-dynamic-require': 'off',
'no-bitwise': 'off',
'no-cond-assign': 'off',
'no-else-return': 'off',
'no-empty': 'off',
'no-labels': 'off',
'no-loop-func': 'off',
'no-mixed-operators': 'off',
'no-multi-assign': 'off',
'no-new-func': 'off',
'no-path-concat': 'off',
'no-prototype-builtins': 'off',
'no-return-assign': 'off',
'no-self-assign': 'off',
'no-shadow-restricted-names': 'off',
'no-unused-expressions': 'off',
'no-use-before-define': 'off',
'no-useless-concat': 'off',
'no-useless-escape': 'off',
radix: 'off',
'unicorn/better-regex': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/empty-brace-spaces': 'off',
'unicorn/escape-case': 'off',
'unicorn/explicit-length-check': 'off',
'unicorn/new-for-builtins': 'off',
'unicorn/no-hex-escape': 'off',
'unicorn/no-instanceof-array': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/no-typeof-undefined': 'off',
'unicorn/no-useless-switch-case': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/prefer-array-find': 'off',
'unicorn/prefer-date-now': 'off',
'unicorn/prefer-default-parameters': 'off',
'unicorn/prefer-logical-operator-over-ternary': 'off',
'unicorn/prefer-native-coercion-functions': 'off',
'unicorn/prefer-negative-index': 'off',
'unicorn/prefer-regexp-test': 'off',
'unicorn/prefer-switch': 'off',
'unicorn/prefer-ternary': 'off',

// TODO rare errors
'arrow-body-style': 'off',
'block-scoped-var': 'off',
'import/no-extraneous-dependencies': 'off',
'import/order': 'off',
'new-cap': 'off',
'newline-per-chained-call': 'off',
'no-extra-boolean-cast': 'off',
'no-redeclare': 'off',
'no-unneeded-ternary': 'off',
'no-useless-return': 'off',
'operator-assignment': 'off',
'unicorn/no-console-spaces': 'off',
yoda: 'off',
},
reportUnusedDisableDirectives: true,
globals: {
jQuery: true,
},
};
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Install dependencies
run: yarn
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
- name: Lint JS and CSS/LESS files
run: npm run lint
test:
Expand All @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [12, 14, 16, 18]
node-version: [12, 14, 16, 18, latest]
steps:
- uses: actions/checkout@v3
- name: Setup Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
ref: develop
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: https://registry.npmjs.org/
- name: pre-setup
run: sh ./scripts/preinstall.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
ref: master
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org/
- name: pre-setup
run: sh ./scripts/preinstall.sh
Expand Down
6 changes: 6 additions & 0 deletions examples/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
globals: {
jQuery: false,
$: true,
},
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@actions/core": "^1.6.0",
"@octokit/core": "^3.6.0",
"@octokit/rest": "^16.16.0",
"better-console": "1.0.1",
"better-console": "^1.0.1",
"browserslist": "^4.19.1",
"del": "^6.1.1",
"extend": "^3.0.2",
Expand All @@ -46,7 +46,7 @@
"gulp-concat-css": "^3.1.0",
"gulp-concat-filenames": "^1.2.0",
"gulp-copy": "^4.0.0",
"gulp-dedupe": "0.0.2",
"gulp-dedupe": "^0.0.2",
"gulp-flatten": "^0.4.0",
"gulp-git": "^2.9.0",
"gulp-header": "^2.0.5",
Expand Down Expand Up @@ -75,7 +75,8 @@
"devDependencies": {
"all-contributors-cli": "^6.7.0",
"auto-changelog": "^2.4.0",
"eslint": "^8.28.0",
"eslint": "^8.29.0",
"eslint-plugin-import": "^2.26.0",
"node-fetch": "^2.6.0",
"postcss": "^8.4.19",
"postcss-less": "^6.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/definitions/modules/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@
var ms1d = 864e5, // milliseconds in a day
ms7d = 7 * ms1d; // milliseconds in a week

// eslint-disable-next-line wrap-iife
return function () { // return a closure so constants get calculated only once
var DC3 = Date.UTC(weekYear, weekMonth, weekDay + 3) / ms1d, // an Absolute Day Number
AWN = Math.floor(DC3 / 7), // an Absolute Week Number
Expand Down
9 changes: 9 additions & 0 deletions tasks/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
rules: {
'no-use-before-define': 'off', // TODO code should be fixed and this ignore removed
},
globals: {
files: true,
Package: true,
},
};
4 changes: 1 addition & 3 deletions tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
These tasks can be imported into your own gulpfile allowing you to avoid using Semantic's build tools

```javascript
var
watch = require('path/to/semantic/tasks/watch')
;
const watch = require('path/to/semantic/tasks/watch');
gulp.task('watch ui', watch);
```
8 changes: 3 additions & 5 deletions tasks/collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ These are collections of tasks that are imported together.

To import them into gulp:
```javascript
var
gulp = require('gulp'),
// modified to point to semantic folder
install = require('tasks/collections/install')
;
const gulp = require('gulp');
// modified to point to semantic folder
const install = require('tasks/collections/install');
gulp = install(gulp);

// tasks are now injected and ready to be used
Expand Down
27 changes: 27 additions & 0 deletions test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
extends: [
'plugin:jest/recommended',
],
settings: {
jest: {
version: 29,
},
},
rules: {
'jest/no-disabled-tests': 'off',

// TODO rare errors
'jest/no-jasmine-globals': 'off',
'jest/no-test-prefixes': 'off',
},
globals: {
jQuery: false,
$: true,
dump: true,
HTTP: true,
jasmine: true,
moduleTests: true,
sandbox: true,
Tinytest: true,
},
};
Loading

0 comments on commit 91ec658

Please sign in to comment.