Skip to content

Commit

Permalink
feat(linter): allow env and globals in overrides configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Feb 6, 2025
1 parent 0df939c commit 12beab8
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 49 deletions.
31 changes: 27 additions & 4 deletions apps/oxlint/fixtures/overrides/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
{
"globals": {
"DefaultFoo": "writeable"
},
"rules": {
"no-var": "error",
"no-console": "error"
},
"overrides": [
{
"files": ["*.js"],
"files": [
"*.js"
],
"rules": {
"no-console": "warn"
}
},
{
"files": ["*.{js,jsx}"],
"files": [
"*.{js,jsx}"
],
"env": {
"es2024": true
},
"globals": {
"ReadFoo": "readonly",
"WriteBar": "writeable",
"NonBaz": "off"
},
"rules": {
"no-console": "off"
}
},
{
"files": ["*.ts"],
"files": [
"*.ts"
],
"env": {
"es2024": false
},
"globals": {
"DefaultFoo": "off"
},
"rules": {
"no-console": "warn"
}
}
]
}
}
28 changes: 25 additions & 3 deletions apps/oxlint/fixtures/overrides/directories-config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
{
"globals": {
"DefaultFoo": "writeable"
},
"rules": {
"no-debugger": "off"
},
"overrides": [
{
"files": ["lib/*.{js,ts}", "src/*"],
"files": [
"lib/*.{js,ts}",
"src/*"
],
"env": {
"es2024": true
},
"globals": {
"ReadFoo": "readonly",
"WriteBar": "writeable",
"NonBaz": "off"
},
"rules": {
"no-debugger": "error"
}
},
{
"files": ["**/tests/*"],
"files": [
"**/tests/*"
],
"env": {
"es2024": false
},
"globals": {
"DefaultFoo": "off"
},
"rules": {
"no-debugger": "warn"
}
}
]
}
}
10 changes: 10 additions & 0 deletions apps/oxlint/fixtures/overrides/other.jsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
var msg = "hello";
console.log(msg);

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultWriteable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'alway-soff';

Check warning on line 12 in apps/oxlint/fixtures/overrides/other.jsx

View workflow job for this annotation

GitHub Actions / Spell Check

"alway" should be "always".
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/overrides/src/oxlint.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// for rules detection
debugger;

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultWriteable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'alway-soff';

Check warning on line 12 in apps/oxlint/fixtures/overrides/src/oxlint.js

View workflow job for this annotation

GitHub Actions / Spell Check

"alway" should be "always".
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/overrides/src/tests/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// for rules detection
debugger;

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultWriteable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'alway-soff';

Check warning on line 12 in apps/oxlint/fixtures/overrides/src/tests/index.js

View workflow job for this annotation

GitHub Actions / Spell Check

"alway" should be "always".
10 changes: 10 additions & 0 deletions apps/oxlint/fixtures/overrides/test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
var msg = "hello";
console.log(msg);

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultWriteable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'alway-soff';

Check warning on line 12 in apps/oxlint/fixtures/overrides/test.js

View workflow job for this annotation

GitHub Actions / Spell Check

"alway" should be "always".
10 changes: 10 additions & 0 deletions apps/oxlint/fixtures/overrides/test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
var msg = "hello";
console.log(msg);

// for env detection
globalThis = 'abc';

// for globals detection
DefaultFoo = 'defaultWriteable';
ReadFoo = 'readable';
console.log(ReadFoo);
WriteBar = 'writeable';
NonBaz = 'alway-soff';

Check warning on line 12 in apps/oxlint/fixtures/overrides/test.ts

View workflow job for this annotation

GitHub Actions / Spell Check

"alway" should be "always".
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ working directory:
`----
help: Replace var with let or const
Found 0 warnings and 1 error.
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/test.js:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----
Found 1 warning and 1 error.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand All @@ -38,10 +47,29 @@ working directory:
1 | var msg = "hello";
2 | console.log(msg);
: ^^^^^^^^^^^
3 |
`----
help: Delete this console statement.
Found 1 warning and 1 error.
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/test.ts:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
,-[fixtures/overrides/test.ts:10:1]
9 | ReadFoo = 'readable';
10 | console.log(ReadFoo);
: ^^^^^^^^^^^
11 | WriteBar = 'writeable';
`----
help: Delete this console statement.
Found 3 warnings and 1 error.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand All @@ -60,7 +88,16 @@ working directory:
`----
help: Replace var with let or const
Found 0 warnings and 1 error.
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/other.jsx:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----
Found 1 warning and 1 error.
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,69 @@ working directory:
help: Delete this code.

x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
,-[fixtures/overrides/src/oxlint.js:1:1]
1 | debugger;
,-[fixtures/overrides/src/oxlint.js:2:1]
1 | // for rules detection
2 | debugger;
: ^^^^^^^^^
3 |
`----
help: Delete this code.
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
,-[fixtures/overrides/src/tests/index.js:1:1]
1 | debugger;
,-[fixtures/overrides/src/tests/index.js:2:1]
1 | // for rules detection
2 | debugger;
: ^^^^^^^^^
3 |
`----
help: Delete this code.

Found 2 warnings and 2 errors.
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/other.jsx:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/src/oxlint.js:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/src/tests/index.js:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/test.js:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-global-assign.html\eslint(no-global-assign)]8;;\: Read-only global 'globalThis' should not be modified.
,-[fixtures/overrides/test.ts:5:1]
4 | // for env detection
5 | globalThis = 'abc';
: ^^^^^|^^^^
: `-- Read-only global 'globalThis' should not be modified.
6 |
`----

Found 7 warnings and 2 errors.
Finished in <variable>ms on 7 files with 96 rules using 1 threads.
----------
CLI result: LintFoundErrors
Expand Down
Loading

0 comments on commit 12beab8

Please sign in to comment.