@evanpurkhiser/oxc-config 0.19.0 → 0.20.0
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/.github/workflows/main.yml +1 -0
- package/package.json +4 -3
- package/src/common.mjs +11 -0
- package/src/oxlint/comments.mjs +73 -0
- package/test/multiline-jsdoc.test.mjs +66 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@evanpurkhiser/oxc-config",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.0",
|
|
5
5
|
"description": "Evan Purkhiser's personal Oxc configuration",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Evan Purkhiser <oxc-config.js@evanpurkhiser.com>",
|
|
@@ -37,9 +37,10 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"lint": "oxlint src oxlint.config.ts profiles/all/oxlint.config.ts",
|
|
40
|
+
"lint": "oxlint src test oxlint.config.ts profiles/all/oxlint.config.ts",
|
|
41
|
+
"test": "node --test",
|
|
41
42
|
"format": "oxfmt .",
|
|
42
43
|
"format:check": "oxfmt --check .",
|
|
43
|
-
"check": "pnpm run lint && pnpm run format:check"
|
|
44
|
+
"check": "pnpm run lint && pnpm test && pnpm run format:check"
|
|
44
45
|
}
|
|
45
46
|
}
|
package/src/common.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {fileURLToPath} from 'node:url';
|
|
2
|
+
|
|
1
3
|
const common = {
|
|
2
4
|
plugins: [
|
|
3
5
|
'eslint',
|
|
@@ -10,7 +12,16 @@ const common = {
|
|
|
10
12
|
'node',
|
|
11
13
|
],
|
|
12
14
|
|
|
15
|
+
jsPlugins: [
|
|
16
|
+
{
|
|
17
|
+
name: 'oxc-config',
|
|
18
|
+
specifier: fileURLToPath(new URL('./oxlint/comments.mjs', import.meta.url)),
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
|
|
13
22
|
rules: {
|
|
23
|
+
'oxc-config/multiline-jsdoc': ['error'],
|
|
24
|
+
|
|
14
25
|
// Best practices
|
|
15
26
|
'array-callback-return': ['warn'],
|
|
16
27
|
'consistent-return': ['warn'],
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const lineBreak = /\r\n|[\r\n\u2028\u2029]/;
|
|
2
|
+
|
|
3
|
+
function expandStandaloneComment(comment, sourceCode) {
|
|
4
|
+
const {start, end} = comment.loc;
|
|
5
|
+
const line = sourceCode.lines[start.line - 1];
|
|
6
|
+
const indentation = line.slice(0, start.column);
|
|
7
|
+
|
|
8
|
+
if (indentation.trim() || line.slice(end.column).trim()) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const content = comment.value.slice(1).trim();
|
|
13
|
+
|
|
14
|
+
// TypeScript reads these directives from the last line of the comment.
|
|
15
|
+
if (/^\**\s*@ts-(?:expect-error|ignore)/.test(comment.value)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const newline = sourceCode.text.match(lineBreak)?.[0] ?? '\n';
|
|
20
|
+
const body = content ? `* ${content}` : '*';
|
|
21
|
+
|
|
22
|
+
return ['/**', `${indentation} ${body}`, `${indentation} */`].join(newline);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const comments = {
|
|
26
|
+
rules: {
|
|
27
|
+
'multiline-jsdoc': {
|
|
28
|
+
meta: {fixable: 'code'},
|
|
29
|
+
create(context) {
|
|
30
|
+
const {sourceCode} = context;
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
Program() {
|
|
34
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
35
|
+
if (comment.type !== 'Block' || !comment.value.startsWith('*')) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const lines = comment.value.split(lineBreak);
|
|
40
|
+
const hasOwnDelimiterLines =
|
|
41
|
+
lines.length >= 3 &&
|
|
42
|
+
lines[0].trim() === '*' &&
|
|
43
|
+
lines.at(-1).trim() === '';
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
hasOwnDelimiterLines &&
|
|
47
|
+
lines.slice(1, -1).every(line => /^\s*\*/.test(line))
|
|
48
|
+
) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const replacement =
|
|
53
|
+
lines.length === 1
|
|
54
|
+
? expandStandaloneComment(comment, sourceCode)
|
|
55
|
+
: undefined;
|
|
56
|
+
|
|
57
|
+
context.report({
|
|
58
|
+
loc: comment.loc,
|
|
59
|
+
message:
|
|
60
|
+
'Use a multiline JSDoc block with delimiters on their own lines and a * on each body line.',
|
|
61
|
+
fix: replacement
|
|
62
|
+
? fixer => fixer.replaceTextRange(comment.range, replacement)
|
|
63
|
+
: undefined,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default comments;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {RuleTester} from 'oxlint/plugins-dev';
|
|
2
|
+
|
|
3
|
+
import {describe, it} from 'node:test';
|
|
4
|
+
|
|
5
|
+
import comments from '../src/oxlint/comments.mjs';
|
|
6
|
+
|
|
7
|
+
RuleTester.describe = describe;
|
|
8
|
+
RuleTester.it = it;
|
|
9
|
+
|
|
10
|
+
const ruleName = 'multiline-jsdoc';
|
|
11
|
+
const tester = new RuleTester({languageOptions: {parserOptions: {lang: 'ts'}}});
|
|
12
|
+
|
|
13
|
+
tester.run(ruleName, comments.rules[ruleName], {
|
|
14
|
+
valid: [
|
|
15
|
+
'/**\n *\n */',
|
|
16
|
+
'/**\r\n * Describes the value.\r\n * @type {number}\r\n */\r\nconst value = 1;',
|
|
17
|
+
'// A line comment.\n/* An ordinary block comment. */',
|
|
18
|
+
"const text = '/** testing */';",
|
|
19
|
+
],
|
|
20
|
+
invalid: [
|
|
21
|
+
{
|
|
22
|
+
code: '/** testing */',
|
|
23
|
+
output: '/**\n * testing\n */',
|
|
24
|
+
errors: 1,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: '/** */\nconst value = 1;',
|
|
28
|
+
output: '/**\n *\n */\nconst value = 1;',
|
|
29
|
+
errors: 1,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'preserves indentation and CRLF when expanding a tag',
|
|
33
|
+
code: 'function getValue() {\r\n /** @type {number} */\r\n const value = 1;\r\n}',
|
|
34
|
+
output:
|
|
35
|
+
'function getValue() {\r\n /**\r\n * @type {number}\r\n */\r\n const value = 1;\r\n}',
|
|
36
|
+
errors: 1,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
code: '/** opening text\n * body\n */',
|
|
40
|
+
output: null,
|
|
41
|
+
errors: 1,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
code: '/**\n * body\n closing text */',
|
|
45
|
+
output: null,
|
|
46
|
+
errors: 1,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: '/**\n body without a star\n */',
|
|
50
|
+
output: null,
|
|
51
|
+
errors: 1,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'preserves inline comments where a newline could change parsing',
|
|
55
|
+
code: 'function getValue() { return /** testing */ 1; }',
|
|
56
|
+
output: null,
|
|
57
|
+
errors: 1,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'preserves TypeScript suppression directives',
|
|
61
|
+
code: '/** @ts-expect-error Intentional type mismatch. */\nconst value: string = 1;',
|
|
62
|
+
output: null,
|
|
63
|
+
errors: 1,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|