@zgeoff/oxlint-config 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/get-imported-name.js +5 -0
- package/max-test-timeout.js +1 -6
- package/no-require.js +111 -0
- package/no-test-sleep.js +1 -6
- package/oxlintrc.json +4 -0
- package/package.json +6 -2
- package/plugin.js +2 -0
- package/react.json +13 -0
- package/setup-test-only.js +1 -6
package/README.md
CHANGED
|
@@ -43,6 +43,10 @@ Or import the config object in `oxlint.config.ts`:
|
|
|
43
43
|
import config from '@zgeoff/oxlint-config';
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
A repo with React extends `./node_modules/@zgeoff/oxlint-config/react.json` after the base config.
|
|
47
|
+
[The React overlay](../../docs/architecture/oxlint-config.md#the-react-overlay) says what it
|
|
48
|
+
changes.
|
|
49
|
+
|
|
46
50
|
The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for configs that want the
|
|
47
51
|
`zgeoff/*` rules without the rest.
|
|
48
52
|
|
|
@@ -54,8 +58,9 @@ The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for confi
|
|
|
54
58
|
direct dependency of the consuming project. Hoisting package managers (bun's default linker, npm)
|
|
55
59
|
resolve it transitively anyway, but isolated layouts (pnpm, `bun install --linker isolated`) fail
|
|
56
60
|
with `Cannot find module '@stylistic/eslint-plugin'` unless it's installed directly.
|
|
57
|
-
- Type-aware rules activate under `oxlint --type-aware
|
|
58
|
-
|
|
61
|
+
- Type-aware rules activate under `oxlint --type-aware`, which needs a type-aware backend: install
|
|
62
|
+
`oxlint-tsgolint`, or install `@maschwenk/tsrslint` and set `OXLINT_TSGOLINT_PATH` to the path
|
|
63
|
+
that its `tsrslint-path` command prints. The config works without a backend.
|
|
59
64
|
|
|
60
65
|
## Rules
|
|
61
66
|
|
|
@@ -70,6 +75,9 @@ The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for confi
|
|
|
70
75
|
- Test files: a test sits beside its module, holds only `setupTest()` and its tests, uses inline
|
|
71
76
|
snapshots, keeps each timeout within its lane's limit, and waits on a condition, never a sleep.
|
|
72
77
|
See [test-file rules](../../docs/architecture/oxlint-config-tests.md).
|
|
78
|
+
- Require functions: `zgeoff/no-require` bans the `require` global and `createRequire`, and
|
|
79
|
+
`import/no-commonjs` bans CommonJS exports. See
|
|
80
|
+
[require functions](../../docs/architecture/oxlint-config.md#require-functions).
|
|
73
81
|
- Import boundaries: `zgeoff/import-zones` fails an import that crosses a declared zone boundary.
|
|
74
82
|
See [import zones](../../docs/architecture/oxlint-config-import-zones.md).
|
|
75
83
|
|
package/max-test-timeout.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
2
|
import buildLaneLimits from './build-lane-limits.js';
|
|
3
|
+
import getImportedName from './get-imported-name.js';
|
|
3
4
|
import resolveSuiteDirectory from './resolve-suite-directory.js';
|
|
4
5
|
|
|
5
6
|
const runnerNames = new Set(['test', 'it', 'describe']);
|
|
@@ -125,12 +126,6 @@ function findVariable(context, identifier) {
|
|
|
125
126
|
return null;
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
function getImportedName(specifier) {
|
|
129
|
-
return specifier.imported.type === 'Identifier'
|
|
130
|
-
? specifier.imported.name
|
|
131
|
-
: specifier.imported.value;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
129
|
function emitTimeouts(context, args, limit) {
|
|
135
130
|
for (const argument of args) {
|
|
136
131
|
const value = argument.type === 'ObjectExpression' ? findTimeoutValue(argument) : argument;
|
package/no-require.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import getImportedName from './get-imported-name.js';
|
|
2
|
+
|
|
3
|
+
const moduleSources = new Set(['node:module', 'module']);
|
|
4
|
+
|
|
5
|
+
const noRequire = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'problem',
|
|
8
|
+
messages: {
|
|
9
|
+
createRequire:
|
|
10
|
+
'Use `import`, never `createRequire`: a require function loads modules that the import rules cannot see.',
|
|
11
|
+
require:
|
|
12
|
+
'Use `import`, never `require`: a require function loads modules that the import rules cannot see.',
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
ImportDeclaration(node) {
|
|
19
|
+
if (node.importKind === 'type' || !moduleSources.has(node.source.value)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for (const variable of context.sourceCode.getDeclaredVariables(node)) {
|
|
24
|
+
emitCreateRequireReads(context, variable);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
'Program:exit'(program) {
|
|
28
|
+
for (const reference of collectRequireReferences(context, program)) {
|
|
29
|
+
context.report({ node: reference.identifier, messageId: 'require' });
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default noRequire;
|
|
37
|
+
|
|
38
|
+
function emitCreateRequireReads(context, variable) {
|
|
39
|
+
const [definition] = variable.defs;
|
|
40
|
+
|
|
41
|
+
if (definition.node.type === 'ImportSpecifier') {
|
|
42
|
+
if (
|
|
43
|
+
definition.node.importKind !== 'type' &&
|
|
44
|
+
getImportedName(definition.node) === 'createRequire'
|
|
45
|
+
) {
|
|
46
|
+
context.report({ node: definition.node, messageId: 'createRequire' });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// a default import of node:module is the same object as its namespace
|
|
53
|
+
for (const reference of variable.references) {
|
|
54
|
+
const node = findCreateRequireRead(reference.identifier);
|
|
55
|
+
|
|
56
|
+
if (node !== null) {
|
|
57
|
+
context.report({ node, messageId: 'createRequire' });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function findCreateRequireRead(object) {
|
|
63
|
+
const parent = object.parent;
|
|
64
|
+
|
|
65
|
+
if (parent.type === 'MemberExpression' && parent.object === object) {
|
|
66
|
+
return isCreateRequireKey(parent.property, parent.computed) ? parent : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const pattern = findDestructuringPattern(parent, object);
|
|
70
|
+
|
|
71
|
+
if (pattern?.type !== 'ObjectPattern') {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
pattern.properties.find(
|
|
77
|
+
(property) =>
|
|
78
|
+
property.type === 'Property' && isCreateRequireKey(property.key, property.computed),
|
|
79
|
+
) ?? null
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function isCreateRequireKey(key, isComputed) {
|
|
84
|
+
return (
|
|
85
|
+
(key.type === 'Literal' && key.value === 'createRequire') ||
|
|
86
|
+
(!isComputed && key.type === 'Identifier' && key.name === 'createRequire')
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function findDestructuringPattern(parent, object) {
|
|
91
|
+
if (parent.type === 'VariableDeclarator' && parent.init === object) {
|
|
92
|
+
return parent.id;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (parent.type === 'AssignmentExpression' && parent.right === object) {
|
|
96
|
+
return parent.left;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// `env.node` declares `require` as a global, so a read resolves to that variable; without it,
|
|
103
|
+
// the read stays unresolved and passes through the global scope
|
|
104
|
+
function collectRequireReferences(context, program) {
|
|
105
|
+
const scope = context.sourceCode.getScope(program);
|
|
106
|
+
const declared = scope.set.get('require');
|
|
107
|
+
const declaredReferences = declared?.defs.length === 0 ? declared.references : [];
|
|
108
|
+
const unresolved = scope.through.filter((reference) => reference.identifier.name === 'require');
|
|
109
|
+
|
|
110
|
+
return [...new Set([...declaredReferences, ...unresolved])];
|
|
111
|
+
}
|
package/no-test-sleep.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
2
|
import findFunctionName from './find-function-name.js';
|
|
3
|
+
import getImportedName from './get-imported-name.js';
|
|
3
4
|
|
|
4
5
|
const testFilePattern = /\.test\.tsx?$/u;
|
|
5
6
|
|
|
@@ -100,12 +101,6 @@ function emitSleepReads(context, variable, names) {
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
function getImportedName(specifier) {
|
|
104
|
-
return specifier.imported.type === 'Identifier'
|
|
105
|
-
? specifier.imported.name
|
|
106
|
-
: specifier.imported.value;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
104
|
function isWrappedTimeout(call) {
|
|
110
105
|
const callee = call.callee;
|
|
111
106
|
const isTimeout =
|
package/oxlintrc.json
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"zgeoff/max-test-timeout": "error",
|
|
41
41
|
"zgeoff/test-timeout-exception-ticket": "error",
|
|
42
42
|
"zgeoff/no-test-sleep": "error",
|
|
43
|
+
"zgeoff/no-require": "error",
|
|
43
44
|
|
|
44
45
|
// name a value for what it holds, in full words: one letter only for a
|
|
45
46
|
// coordinate, zod's `z`, Bun's shell `$` or an unread `_` placeholder, and
|
|
@@ -107,6 +108,9 @@
|
|
|
107
108
|
"typescript/consistent-type-assertions": ["error", { "assertionStyle": "never" }],
|
|
108
109
|
"typescript/no-unsafe-type-assertion": "off",
|
|
109
110
|
"import/no-cycle": "error",
|
|
111
|
+
"import/no-commonjs": "error",
|
|
112
|
+
// zod's documented import form is `import * as z from 'zod'`
|
|
113
|
+
"import/no-namespace": ["error", { "ignore": ["zod", "zod/*"] }],
|
|
110
114
|
|
|
111
115
|
"no-shadow": "error",
|
|
112
116
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"oxlintrc.json",
|
|
13
|
+
"react.json",
|
|
13
14
|
"plugin.js",
|
|
14
15
|
"function-verb.js",
|
|
15
16
|
"verb-contract.js",
|
|
@@ -35,6 +36,8 @@
|
|
|
35
36
|
"build-lane-limits.js",
|
|
36
37
|
"resolve-suite-directory.js",
|
|
37
38
|
"no-test-sleep.js",
|
|
39
|
+
"no-require.js",
|
|
40
|
+
"get-imported-name.js",
|
|
38
41
|
"import-zones.js",
|
|
39
42
|
"import-zones-schema.js",
|
|
40
43
|
"import-zones-entry.js",
|
|
@@ -55,6 +58,7 @@
|
|
|
55
58
|
"exports": {
|
|
56
59
|
".": "./index.js",
|
|
57
60
|
"./oxlintrc.json": "./oxlintrc.json",
|
|
61
|
+
"./react.json": "./react.json",
|
|
58
62
|
"./plugin": "./plugin.js",
|
|
59
63
|
"./import-zones": {
|
|
60
64
|
"types": "./import-zones-entry.d.ts",
|
|
@@ -71,7 +75,7 @@
|
|
|
71
75
|
"@stylistic/eslint-plugin": "5.10.0"
|
|
72
76
|
},
|
|
73
77
|
"devDependencies": {
|
|
74
|
-
"@types/bun": "1.4.
|
|
78
|
+
"@types/bun": "1.4.3",
|
|
75
79
|
"tsrs": "0.18.0-ts7.1.0-dev.20260929",
|
|
76
80
|
"typescript": "7.0.2"
|
|
77
81
|
},
|
package/plugin.js
CHANGED
|
@@ -9,6 +9,7 @@ import noCommentRuleOverride from './no-comment-rule-override.js';
|
|
|
9
9
|
import noFileSnapshot from './no-file-snapshot.js';
|
|
10
10
|
import noHiddenCast from './no-hidden-cast.js';
|
|
11
11
|
import noJSDoc from './no-jsdoc.js';
|
|
12
|
+
import noRequire from './no-require.js';
|
|
12
13
|
import noRestrictedWords from './no-restricted-words.js';
|
|
13
14
|
import noTestSleep from './no-test-sleep.js';
|
|
14
15
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
@@ -110,6 +111,7 @@ const plugin = {
|
|
|
110
111
|
'max-test-timeout': buildMaxTestTimeout(resolveRepoRoot),
|
|
111
112
|
'test-timeout-exception-ticket': testTimeoutExceptionTicket,
|
|
112
113
|
'no-test-sleep': noTestSleep,
|
|
114
|
+
'no-require': noRequire,
|
|
113
115
|
'import-zones': importZones,
|
|
114
116
|
},
|
|
115
117
|
};
|
package/react.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
|
|
3
|
+
"plugins": ["react"],
|
|
4
|
+
"rules": {
|
|
5
|
+
// React 17's JSX runtime and later need no React in scope
|
|
6
|
+
"react/react-in-jsx-scope": "off",
|
|
7
|
+
// forwarding a whole props object is how a component wraps another, more so with
|
|
8
|
+
// zgeoff/no-destructured-params in force
|
|
9
|
+
"react/jsx-props-no-spreading": "off",
|
|
10
|
+
// form and layout composition nests deeper than any fixed limit
|
|
11
|
+
"react/jsx-max-depth": "off"
|
|
12
|
+
}
|
|
13
|
+
}
|
package/setup-test-only.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
|
+
import getImportedName from './get-imported-name.js';
|
|
2
3
|
|
|
3
4
|
const testFilePattern = /\.test\.tsx?$/u;
|
|
4
5
|
|
|
@@ -95,12 +96,6 @@ function collectTestNames(context, program) {
|
|
|
95
96
|
return new Set(names);
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
function getImportedName(specifier) {
|
|
99
|
-
return specifier.imported.type === 'Identifier'
|
|
100
|
-
? specifier.imported.name
|
|
101
|
-
: specifier.imported.value;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
99
|
// ESM puts module-level bindings in a module scope nested under the global one
|
|
105
100
|
function hasModuleBinding(context, program, name) {
|
|
106
101
|
const scope = context.sourceCode.getScope(program);
|