@zgeoff/oxlint-config 0.2.7 → 0.2.8
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 +21 -1
- package/no-restricted-words.js +61 -0
- package/package.json +2 -1
- package/plugin.js +2 -0
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ await arguments, awaits hidden inside a control-flow condition or a `&&`/`||`/`?
|
|
|
8
8
|
`switch` statement, every JSDoc block, any run of more than three line comments, and a repo config
|
|
9
9
|
that loosens either comment rule. `zgeoff/function-verb` enforces the function-naming taxonomy from
|
|
10
10
|
the shared agent guidelines, `zgeoff/test-beside-module` keeps each test file beside the module it
|
|
11
|
-
tests, `zgeoff/import-zones` fails an import that crosses a module boundary the repo declares,
|
|
11
|
+
tests, `zgeoff/import-zones` fails an import that crosses a module boundary the repo declares,
|
|
12
|
+
`zgeoff/no-restricted-words` keeps the words in its `words` option out of a path's text, and
|
|
12
13
|
`zgeoff/no-file-snapshot` bans file snapshots.
|
|
13
14
|
|
|
14
15
|
## Usage
|
|
@@ -86,6 +87,25 @@ first statement, so put the comment above it:
|
|
|
86
87
|
A second test file for a module (`<name>.host.test.ts`) needs its own `<name>.host.<ext>`, so the
|
|
87
88
|
rule reports it beside only `<name>.ts`.
|
|
88
89
|
|
|
90
|
+
## `zgeoff/no-restricted-words`
|
|
91
|
+
|
|
92
|
+
Off unless a repo configures it. The `words` option lists the words to keep out of the text of a
|
|
93
|
+
file: string literals, template text and comments. A word matches whole and without case, so `imp`
|
|
94
|
+
reports `'IMP daemon'` and `'imp-e2e'` but not `'impl'` or `'imp_name'`. Identifiers are code, not
|
|
95
|
+
text, and the rule never reads them. Scope the rule to a path with `overrides`, and turn it off for
|
|
96
|
+
the paths that may name the words:
|
|
97
|
+
|
|
98
|
+
```jsonc
|
|
99
|
+
{
|
|
100
|
+
"rules": {
|
|
101
|
+
"zgeoff/no-restricted-words": ["error", { "words": ["imp", "impd"] }],
|
|
102
|
+
},
|
|
103
|
+
"overrides": [
|
|
104
|
+
{ "files": ["packages/execution/**"], "rules": { "zgeoff/no-restricted-words": "off" } },
|
|
105
|
+
],
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
89
109
|
## `zgeoff/no-file-snapshot`
|
|
90
110
|
|
|
91
111
|
Snapshots are inline only, so the golden value sits in the test that pins it. The rule reports every
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const noRestrictedWords = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
messages: {
|
|
5
|
+
restricted:
|
|
6
|
+
'Remove `{{word}}` from this {{place}}: the repo config restricts the word in this path.',
|
|
7
|
+
},
|
|
8
|
+
schema: [
|
|
9
|
+
{
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
words: { type: 'array', items: { type: 'string', minLength: 1 }, uniqueItems: true },
|
|
13
|
+
},
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
create(context) {
|
|
19
|
+
const words = context.options[0]?.words ?? [];
|
|
20
|
+
|
|
21
|
+
if (words.length === 0) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const pattern = buildWordPattern(words);
|
|
26
|
+
|
|
27
|
+
const checkText = (node, text, place) => {
|
|
28
|
+
for (const match of text.matchAll(pattern)) {
|
|
29
|
+
context.report({ node, messageId: 'restricted', data: { word: match[0], place } });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
Literal(node) {
|
|
35
|
+
if (typeof node.value === 'string') {
|
|
36
|
+
checkText(node, node.value, 'string');
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
TemplateElement(node) {
|
|
40
|
+
checkText(node, node.value.cooked ?? node.value.raw, 'template');
|
|
41
|
+
},
|
|
42
|
+
Program() {
|
|
43
|
+
for (const comment of context.sourceCode.getAllComments()) {
|
|
44
|
+
checkText(comment, comment.value, 'comment');
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// a letter, digit or underscore on either side makes the match part of a
|
|
52
|
+
// longer word (`impl`, `simple`), so only those characters bound it
|
|
53
|
+
function buildWordPattern(words) {
|
|
54
|
+
const alternatives = words.map((word) =>
|
|
55
|
+
word.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return new RegExp(`(?<![\\p{L}\\p{N}_])(?:${alternatives.join('|')})(?![\\p{L}\\p{N}_])`, 'giu');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default noRestrictedWords;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"oxlintrc.json",
|
|
13
13
|
"plugin.js",
|
|
14
14
|
"function-verb.js",
|
|
15
|
+
"no-restricted-words.js",
|
|
15
16
|
"max-consecutive-line-comments.js",
|
|
16
17
|
"no-jsdoc.js",
|
|
17
18
|
"no-comment-rule-override.js",
|
package/plugin.js
CHANGED
|
@@ -4,6 +4,7 @@ import maxConsecutiveLineComments from './max-consecutive-line-comments.js';
|
|
|
4
4
|
import noCommentRuleOverride from './no-comment-rule-override.js';
|
|
5
5
|
import noFileSnapshot from './no-file-snapshot.js';
|
|
6
6
|
import noJSDoc from './no-jsdoc.js';
|
|
7
|
+
import noRestrictedWords from './no-restricted-words.js';
|
|
7
8
|
import testBesideModule from './test-beside-module.js';
|
|
8
9
|
|
|
9
10
|
// custom rules loaded through oxlint's jsPlugins (ESLint v9 rule API): each
|
|
@@ -105,6 +106,7 @@ const plugin = {
|
|
|
105
106
|
'max-consecutive-line-comments': maxConsecutiveLineComments,
|
|
106
107
|
'no-comment-rule-override': noCommentRuleOverride,
|
|
107
108
|
'function-verb': functionVerb,
|
|
109
|
+
'no-restricted-words': noRestrictedWords,
|
|
108
110
|
'test-beside-module': testBesideModule,
|
|
109
111
|
'no-file-snapshot': noFileSnapshot,
|
|
110
112
|
'import-zones': importZones,
|