Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: target ESLint v9 #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

7 changes: 7 additions & 0 deletions .labrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
'lint-options': JSON.stringify({
ignores: ['test/**/fixtures']
})
};
25 changes: 17 additions & 8 deletions lib/configs/module.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
'use strict';

module.exports = {
parser: '@babel/eslint-parser',
extends: 'plugin:@hapi/recommended',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'script',
requireConfigFile: false
}
const BabelParser = require('@babel/eslint-parser');

module.exports = function (plugin) {

return [
...plugin.configs.recommended,
{
languageOptions: {
parser: BabelParser,
parserOptions: {
requireConfigFile: false
},
ecmaVersion: 2020,
sourceType: 'script'
}
}
];
};
226 changes: 117 additions & 109 deletions lib/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -1,112 +1,120 @@
'use strict';

module.exports = {
plugins: ['@hapi'],
env: {
node: true,
es2020: true
},
parserOptions: {
ecmaVersion: 2020
},
rules: {
'@hapi/capitalize-modules': ['warn', 'global-scope-only'],
'@hapi/for-loop': ['warn', { maxDepth: 3, startIterator: 'i' }],
'@hapi/no-var': 'error',
'@hapi/scope-start': 'warn',
'@hapi/no-arrowception': 'error',
'camelcase': 'off',
'consistent-return': 'off',
'vars-on-top': 'off',
'new-cap': 'off',
'no-console': 'off',
'no-constant-condition': 'error',
'no-empty': 'off',
'no-native-reassign': 'off',
'no-underscore-dangle': 'off',
'no-undef': ['error', { typeof: false }],
'no-process-exit': 'off',
'no-unused-expressions': 'off',
'no-regex-spaces': 'off',
'no-catch-shadow': 'off',
'no-lonely-if': 'off',
'brace-style': ['warn', 'stroustrup'],
'no-shadow': ['warn', { allow: ['err', 'done'] }],
'no-unused-vars': ['warn', { vars: 'all', varsIgnorePattern: '^internals$', args: 'none' }],
'one-var': ['error', 'never'],
'handle-callback-err': ['error', '^(e|err|error)$'],
'array-bracket-spacing': 'warn',
'dot-notation': 'warn',
'eol-last': 'warn',
'no-trailing-spaces': 'warn',
'no-eq-null': 'warn',
'no-extend-native': 'warn',
'no-redeclare': 'warn',
'no-loop-func': 'warn',
'yoda': ['warn', 'never'],
'sort-vars': 'warn',
'arrow-parens': ['error', 'always'],
'arrow-spacing': ['error', { before: true, after: true }],
'quotes': ['error', 'single', { allowTemplateLiterals: true }],
'consistent-this': ['error', 'self'],
'new-parens': 'error',
'no-array-constructor': 'error',
'no-confusing-arrow': 'error',
'no-new-object': 'error',
'no-spaced-func': 'error',
'no-mixed-spaces-and-tabs': 'error',
'key-spacing': 'error',
'keyword-spacing': ['error', { before: true, after: true }],
'semi': ['error', 'always'],
'semi-spacing': ['error', { before: false, after: true }],
'space-before-blocks': 'error',
'space-infix-ops': 'error',
'space-unary-ops': ['warn', { words: true, nonwords: false }],
'strict': ['error', 'global'],
'eqeqeq': 'error',
'curly': ['error', 'all'],
'no-eval': 'error',
'no-else-return': 'error',
'no-return-assign': 'error',
'no-new-wrappers': 'error',
'comma-dangle': ['error', 'never'],
'no-sparse-arrays': 'error',
'no-ex-assign': 'error',
'prefer-arrow-callback': 'error',
'prefer-const': ['error', { destructuring: 'all' }],
'indent': ['error', 4, { SwitchCase: 1 }],
'space-before-function-paren': ['error', { anonymous: 'always', named: 'never' }],
'func-style': ['error', 'expression'],
'object-curly-spacing': ['error', 'always'],
'object-shorthand': ['error', 'properties'],
'no-unsafe-finally': 'error',
'no-useless-computed-key': 'error',
'require-await': 'error',
'constructor-super': 'error',
'no-buffer-constructor': 'error',
'no-mixed-requires': 'error',
'no-new-require': 'error',
'no-caller': 'error',
'no-const-assign': 'error',
'no-dupe-class-members': 'error',
'no-class-assign': 'warn',
'no-new-symbol': 'error',
'no-this-before-super': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'no-useless-call': 'error',
'rest-spread-spacing': ['error', 'never'],
'no-extra-semi': 'error',
'no-dupe-keys': 'error',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'directive', next: '*' },
{ blankLine: 'any', prev: 'directive', next: 'directive' },
{ blankLine: 'always', prev: 'cjs-import', next: '*' },
{ blankLine: 'any', prev: 'cjs-import', next: 'cjs-import' },
{ blankLine: 'always', prev: 'cjs-export', next: '*' },
{ blankLine: 'always', prev: 'multiline-block-like', next: '*' },
{ blankLine: 'always', prev: 'class', next: '*' }
]
}
const Globals = require('globals');

module.exports = function (plugin) {

return [{
plugins: {
'@hapi': plugin
},
languageOptions: {
ecmaVersion: 2020,
sourceType: 'script',
globals: {
...Globals.es2020,
...Globals.node
}
},
rules: {
'@hapi/capitalize-modules': ['warn', 'global-scope-only'],
'@hapi/for-loop': ['warn', { maxDepth: 3, startIterator: 'i' }],
'@hapi/no-var': 'error',
'@hapi/scope-start': 'warn',
'@hapi/no-arrowception': 'error',
'camelcase': 'off',
'consistent-return': 'off',
'vars-on-top': 'off',
'new-cap': 'off',
'no-console': 'off',
'no-constant-condition': 'error',
'no-empty': 'off',
'no-native-reassign': 'off',
'no-underscore-dangle': 'off',
'no-undef': ['error', { typeof: false }],
'no-process-exit': 'off',
'no-unused-expressions': 'off',
'no-regex-spaces': 'off',
'no-catch-shadow': 'off',
'no-lonely-if': 'off',
'brace-style': ['warn', 'stroustrup'],
'no-shadow': ['warn', { allow: ['err', 'done'] }],
'no-unused-vars': ['warn', { vars: 'all', caughtErrors: 'all', varsIgnorePattern: '^internals$', args: 'none' }],
'one-var': ['error', 'never'],
'handle-callback-err': ['error', '^(e|err|error)$'],
'array-bracket-spacing': 'warn',
'dot-notation': 'warn',
'eol-last': 'warn',
'no-trailing-spaces': 'warn',
'no-eq-null': 'warn',
'no-extend-native': 'warn',
'no-redeclare': 'warn',
'no-loop-func': 'warn',
'yoda': ['warn', 'never'],
'sort-vars': 'warn',
'arrow-parens': ['error', 'always'],
'arrow-spacing': ['error', { before: true, after: true }],
'quotes': ['error', 'single', { allowTemplateLiterals: true }],
'consistent-this': ['error', 'self'],
'new-parens': 'error',
'no-array-constructor': 'error',
'no-confusing-arrow': 'error',
'no-new-object': 'error',
'no-spaced-func': 'error',
'no-mixed-spaces-and-tabs': 'error',
'key-spacing': 'error',
'keyword-spacing': ['error', { before: true, after: true }],
'semi': ['error', 'always'],
'semi-spacing': ['error', { before: false, after: true }],
'space-before-blocks': 'error',
'space-infix-ops': 'error',
'space-unary-ops': ['warn', { words: true, nonwords: false }],
'strict': ['error', 'global'],
'eqeqeq': 'error',
'curly': ['error', 'all'],
'no-eval': 'error',
'no-else-return': 'error',
'no-return-assign': 'error',
'no-new-wrappers': 'error',
'comma-dangle': ['error', 'never'],
'no-sparse-arrays': 'error',
'no-ex-assign': 'error',
'prefer-arrow-callback': 'error',
'prefer-const': ['error', { destructuring: 'all' }],
'indent': ['error', 4, { SwitchCase: 1 }],
'space-before-function-paren': ['error', { anonymous: 'always', named: 'never' }],
'func-style': ['error', 'expression'],
'object-curly-spacing': ['error', 'always'],
'object-shorthand': ['error', 'properties'],
'no-unsafe-finally': 'error',
'no-useless-computed-key': 'error',
'require-await': 'error',
'constructor-super': 'error',
'no-buffer-constructor': 'error',
'no-mixed-requires': 'error',
'no-new-require': 'error',
'no-caller': 'error',
'no-const-assign': 'error',
'no-dupe-class-members': 'error',
'no-class-assign': 'warn',
'no-new-symbol': 'error',
'no-this-before-super': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'no-useless-call': 'error',
'rest-spread-spacing': ['error', 'never'],
'no-extra-semi': 'error',
'no-dupe-keys': 'error',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'directive', next: '*' },
{ blankLine: 'any', prev: 'directive', next: 'directive' },
{ blankLine: 'always', prev: 'cjs-import', next: '*' },
{ blankLine: 'any', prev: 'cjs-import', next: 'cjs-import' },
{ blankLine: 'always', prev: 'cjs-export', next: '*' },
{ blankLine: 'always', prev: 'multiline-block-like', next: '*' },
{ blankLine: 'always', prev: 'class', next: '*' }
]
}
}];
};
29 changes: 15 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ const Module = require('./configs/module');
const ScopeStart = require('./rules/scope-start');


const internals = {};


module.exports = {
configs: {
recommended: Recommended,
module: Module
},
rules: {
'capitalize-modules': CapitalizeModules,
'for-loop': ForLoop,
'no-var': NoVar,
'scope-start': ScopeStart,
'no-arrowception': NoArrowception
const internals = {
plugin: {
configs: {},
rules: {
'capitalize-modules': CapitalizeModules,
'for-loop': ForLoop,
'no-var': NoVar,
'scope-start': ScopeStart,
'no-arrowception': NoArrowception
}
}
};

internals.plugin.configs.recommended = Recommended(internals.plugin);
internals.plugin.configs.module = Module(internals.plugin);

module.exports = internals.plugin;
8 changes: 5 additions & 3 deletions lib/rules/capitalize-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = {
},
create(context) {

const sourceCode = context.sourceCode ?? context.getSourceCode();

const globalScopeOnly = context.options[0] === 'global-scope-only';

const isCapitalized = function (name) {
Expand All @@ -47,15 +49,15 @@ module.exports = {
node.callee.name === 'require';
};

const atTopLevel = function () {
const atTopLevel = function (node) {

return context.getAncestors().every((parent) => internals.validTopLevelParents.has(parent.type));
return (sourceCode.getAncestors ? sourceCode.getAncestors(node) : context.getAncestors()).every((parent) => internals.validTopLevelParents.has(parent.type));
};

const check = function (node) {

if (globalScopeOnly === true &&
atTopLevel() === false) {
atTopLevel(node) === false) {

return;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ module.exports = {
},
create(context) {

const sourceCode = context.sourceCode ?? context.getSourceCode();

const check = (node) => {

if (node.parent.parent &&
(node.parent.parent.type === 'TryStatement' ||
node.parent.parent.type === 'CatchClause')) {

const variables = context.getDeclaredVariables(node);
const variables = sourceCode.getDeclaredVariables ? sourceCode.getDeclaredVariables(node, context) : context.getDeclaredVariables();
const scopeNode = internals.getScopeNode(node);
if (variables.some(internals.isUsedFromOutsideOf(scopeNode))) {
return;
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/scope-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
},
create(context) {

const sourceCode = context.sourceCode ?? context.getSourceCode();

const maxInOneLiner = context.options[1] !== undefined ? context.options[1] : 1;

const checkFunction = function (node) {
Expand Down Expand Up @@ -58,8 +60,8 @@ module.exports = {

const stmt = body[0];
const bodyStartLine = stmt.loc.start.line;
const openTokenLine = context.getTokenBefore(stmt).loc.start.line;
const closeTokenLine = isBlockBody ? context.getTokenAfter(stmt).loc.start.line : context.getLastToken(stmt).loc.start.line;
const openTokenLine = sourceCode.getTokenBefore(stmt).loc.start.line;
const closeTokenLine = isBlockBody ? sourceCode.getTokenAfter(stmt).loc.start.line : sourceCode.getLastToken(stmt).loc.start.line;

if (allowOneLiners === true &&
body.length <= maxInOneLiner &&
Expand Down
Loading
Loading