Skip to content

Upgrade to ESLint 9 #24

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

Open
wants to merge 7 commits into
base: main
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
6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
NODE_VERSION: [16.x]
NODE_VERSION: [22.x]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
npm-debug.log
package-lock.json
yarn.lock
.idea
/test/fixtures
23 changes: 23 additions & 0 deletions copy-fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from "node:fs/promises";
import path from "node:path";

const fixtures = path.join( ".", "test", "fixtures" );

try {
await fs.mkdir( fixtures );
} catch ( _ ) {
await fs.rm(
fixtures,
{
recursive: true
}
);
}

await fs.cp(
path.join( ".", "node_modules", "jquery", "src" ),
path.join( fixtures, "src" ),
{
recursive: true
}
);
26 changes: 26 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import jquery from "./index.js";
import globals from "globals";
import stylistic from "@stylistic/eslint-plugin-js";

export default [
jquery,
{
files: [ "!test/**" ],
plugins: {
"@stylistic/js": stylistic
},
rules: {
"@stylistic/js/indent": [ "error", "tab" ],
"@stylistic/js/quote-props": [ "error", "as-needed" ]
}
},
{
files: [ "test/**" ],
languageOptions: {
globals: {
...globals.amd,
...globals.browser
}
}
}
];
70 changes: 38 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
module.exports = {
import stylistic from "@stylistic/eslint-plugin-js";

export default {
plugins: {
"@stylistic/js": stylistic
},
rules: {
"no-negated-in-lhs": "error",
"no-unsafe-negation": "error",
"no-cond-assign": [ "error", "except-parens" ],
curly: [ "error", "all" ],
"object-curly-spacing": [ "error", "always" ],
"computed-property-spacing": [ "error", "always" ],
"array-bracket-spacing": [ "error", "always" ],
"@stylistic/js/object-curly-spacing": [ "error", "always" ],
"@stylistic/js/computed-property-spacing": [ "error", "always" ],
"@stylistic/js/array-bracket-spacing": [ "error", "always" ],
eqeqeq: [ "error", "smart" ],
"no-unused-expressions": "error",
"no-sequences": "error",
"no-nested-ternary": "error",
"no-unreachable": "error",
"wrap-iife": [ "error", "inside" ],
"@stylistic/js/wrap-iife": [ "error", "inside" ],
"no-caller": "error",
quotes: [ "error", "double" ],
"@stylistic/js/quotes": [ "error", "double" ],
"no-undef": "error",
"no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_"
argsIgnorePattern: "^_",
caughtErrors: "none"
}
],
"operator-linebreak": [ "error", "after" ],
"comma-style": [ "error", "last" ],
"@stylistic/js/operator-linebreak": [ "error", "after" ],
"@stylistic/js/comma-style": [ "error", "last" ],
camelcase: [
"error",
{
Expand All @@ -36,7 +42,7 @@ module.exports = {
allowPattern: "^[a-z]+(_[a-z]+)+$"
}
],
"max-len": [
"@stylistic/js/max-len": [
"error",
{
code: 100,
Expand All @@ -45,24 +51,24 @@ module.exports = {
ignoreRegExpLiterals: true
}
],
"no-mixed-spaces-and-tabs": "error",
"no-trailing-spaces": "error",
"@stylistic/js/no-mixed-spaces-and-tabs": "error",
"@stylistic/js/no-trailing-spaces": "error",
"no-irregular-whitespace": "error",
"no-multi-str": "error",
"comma-dangle": [ "error", "never" ],
"comma-spacing": [
"@stylistic/js/comma-dangle": [ "error", "never" ],
"@stylistic/js/comma-spacing": [
"error",
{
before: false,
after: true
}
],
"space-before-blocks": [ "error", "always" ],
"space-in-parens": [ "error", "always" ],
"keyword-spacing": [ 2 ],
"template-curly-spacing": [ "error", "always" ],
semi: [ "error", "always" ],
"semi-spacing": [
"@stylistic/js/space-before-blocks": [ "error", "always" ],
"@stylistic/js/space-in-parens": [ "error", "always" ],
"@stylistic/js/keyword-spacing": [ 2 ],
"@stylistic/js/template-curly-spacing": [ "error", "always" ],
"@stylistic/js/semi": [ "error", "always" ],
"@stylistic/js/semi-spacing": [
"error",
{

Expand All @@ -71,35 +77,35 @@ module.exports = {
after: true
}
],
"no-extra-semi": "error",
"space-infix-ops": "error",
"eol-last": "error",
"lines-around-comment": [
"@stylistic/js/no-extra-semi": "error",
"@stylistic/js/space-infix-ops": "error",
"@stylistic/js/eol-last": "error",
"@stylistic/js/lines-around-comment": [
"error",
{
beforeLineComment: true
}
],
"linebreak-style": [ "error", "unix" ],
"@stylistic/js/linebreak-style": [ "error", "unix" ],
"no-with": "error",
"brace-style": "error",
"space-before-function-paren": [ "error", "never" ],
"@stylistic/js/brace-style": "error",
"@stylistic/js/space-before-function-paren": [ "error", "never" ],
"no-loop-func": "error",
"no-spaced-func": "error",
"key-spacing": [
"@stylistic/js/function-call-spacing": [ "error", "never" ],
"@stylistic/js/key-spacing": [
"error",
{
beforeColon: false,
afterColon: true
}
],
"space-unary-ops": [
"@stylistic/js/space-unary-ops": [
"error",
{
words: false,
nonwords: false
}
],
"no-multiple-empty-lines": 2
"@stylistic/js/no-multiple-empty-lines": 2
}
};
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"version": "3.0.2",
"description": "jQuery eslint config",
"main": "index.js",
"type": "module",
"scripts": {
"test": "eslint ."
"test": "npm run copy-fixtures && npm run lint",
"lint": "eslint",
"copy-fixtures": "node copy-fixtures.js"
},
"repository": {
"type": "git",
Expand All @@ -25,7 +28,14 @@
],
"author": "Gaidarenko Oleg <markelog@gmail.com>",
"license": "MIT",
"dependencies": {
"@stylistic/eslint-plugin-js": "^2.9.0"
},
"peerDependencies": {
"eslint": ">=9.0.0"
},
"devDependencies": {
"eslint": "^8.5.0"
"eslint": "^9.12.0",
"jquery": "latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to provide a concrete version here, even without the ^ range. This is because code style changes are not breaking and may happen even in patch releases, breaking the build.

}
}
18 changes: 13 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
npm install --save-dev eslint-config-jquery
```

Configure ESLint with a `.eslintrc` file using the following contents:
```json
{
"extends": "jquery"
}
Version 4.0.0 or newer work with ESLint version 9.0.0 or newer and require using the flat config. Use version 3.x for older ESLint versions.

In your `eslint.config file`, import it and add it to your flat config array.

```javascript
import jquery from "eslint-config-jquery";

export default [
// ... any other configurations,
jquery,
// ... any other configurations
];
Comment on lines +16 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timmywil that's probably a good idea; the way we use the config is too "picky"; we should perhaps just apply it on a global level and then provide overrides in separate blocks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At my workplace, we use eslint-config-jquery as one of the base sets of rules, then override a handful of them that we disagree with. It looks like this:

const base = {
    plugins: {
        '@stylistic/js': stylistic,
        jsdoc
    },
    rules: {
        'no-unused-expressions': [
            'error',
            {
                'allowShortCircuit': true
            }
        ],
        '@stylistic/js/quotes': [
            'error',
            'single',
            {
                'avoidEscape': true,
                'allowTemplateLiterals': true
            }
        ],
        '@stylistic/js/linebreak-style': 'off',
        'jsdoc/tag-lines': 0,
        'jsdoc/no-defaults': 0
..... more stuff here .....
};

..... more stuff here ....

export default [
    ignores, // note: this must go first for it to be applied globally
    js.configs.recommended,
    jquery,
    jsdoc.configs[ 'flat/recommended-typescript-flavor' ],
    base,
    overrideForUnitTests  // this has a "files" selector for unit tests and exempts them from jsdoc and max-len
];


```

## Status
Expand Down
Empty file added test/.gitkeep
Empty file.
21 changes: 0 additions & 21 deletions test/fixtures/.eslintrc.js

This file was deleted.

Loading
Loading