@evanpurkhiser/oxc-config 0.19.0 → 0.21.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.
@@ -14,6 +14,7 @@ jobs:
14
14
  persist-credentials: false
15
15
  - uses: jdx/mise-action@v4.2.0
16
16
  - run: pnpm install --frozen-lockfile
17
+ - run: pnpm test
17
18
  - run: prek run --all-files
18
19
 
19
20
  publish:
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.19.0",
4
+ "version": "0.21.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,17 @@ const common = {
10
12
  'node',
11
13
  ],
12
14
 
15
+ jsPlugins: [
16
+ {
17
+ name: 'oxc-config',
18
+ specifier: fileURLToPath(new URL('./oxlint/plugin.mjs', import.meta.url)),
19
+ },
20
+ ],
21
+
13
22
  rules: {
23
+ 'oxc-config/multiline-jsdoc': ['error'],
24
+ 'oxc-config/no-multiline-nested-call': ['error'],
25
+
14
26
  // Best practices
15
27
  'array-callback-return': ['warn'],
16
28
  'consistent-return': ['warn'],
@@ -19,6 +31,7 @@ const common = {
19
31
  'no-extra-label': ['error'],
20
32
  'no-implied-eval': ['error'],
21
33
  'no-lone-blocks': ['error'],
34
+ 'no-lonely-if': ['error'],
22
35
  'no-self-compare': ['error'],
23
36
  'no-sequences': ['error'],
24
37
  'no-useless-call': ['warn'],
@@ -69,6 +82,7 @@ const common = {
69
82
  'typescript/no-useless-constructor': ['error'],
70
83
  'typescript/array-type': ['error', {default: 'array-simple'}],
71
84
  'typescript/consistent-type-imports': ['error'],
85
+ 'typescript/consistent-type-definitions': ['error', 'interface'],
72
86
  'typescript/no-import-type-side-effects': ['error'],
73
87
  'typescript/no-non-null-asserted-optional-chain': ['error'],
74
88
  'typescript/no-non-null-asserted-nullish-coalescing': ['error'],
@@ -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,29 @@
1
+ export default {
2
+ meta: {
3
+ messages: {
4
+ extractCall: 'Assign the multiline call result to a variable before passing it.',
5
+ },
6
+ },
7
+ create(context) {
8
+ return {
9
+ CallExpression(node) {
10
+ if (node.arguments.length !== 1) {
11
+ return;
12
+ }
13
+
14
+ const [argument] = node.arguments;
15
+ const expression =
16
+ argument.type === 'ChainExpression' ? argument.expression : argument;
17
+
18
+ if (
19
+ expression.type !== 'CallExpression' ||
20
+ argument.loc.start.line === argument.loc.end.line
21
+ ) {
22
+ return;
23
+ }
24
+
25
+ context.report({node: argument, messageId: 'extractCall'});
26
+ },
27
+ };
28
+ },
29
+ };
@@ -0,0 +1,9 @@
1
+ import comments from './comments.mjs';
2
+ import noMultilineNestedCall from './no-multiline-nested-call.mjs';
3
+
4
+ export default {
5
+ rules: {
6
+ ...comments.rules,
7
+ 'no-multiline-nested-call': noMultilineNestedCall,
8
+ },
9
+ };
@@ -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
+ });
@@ -0,0 +1,38 @@
1
+ import {RuleTester} from 'oxlint/plugins-dev';
2
+
3
+ import {describe, it} from 'node:test';
4
+
5
+ import plugin from '../src/oxlint/plugin.mjs';
6
+
7
+ RuleTester.describe = describe;
8
+ RuleTester.it = it;
9
+
10
+ const ruleName = 'no-multiline-nested-call';
11
+ const tester = new RuleTester({languageOptions: {parserOptions: {lang: 'ts'}}});
12
+
13
+ tester.run(ruleName, plugin.rules[ruleName], {
14
+ valid: [
15
+ 'send();',
16
+ 'send(\n format(value),\n);',
17
+ 'send({\n value,\n});',
18
+ 'items.map(item => {\n return format(item);\n});',
19
+ 'send(topic, format({\n value,\n}));',
20
+ 'send(...format({\n value,\n}));',
21
+ 'send(format?.({\n value,\n}).text);',
22
+ 'const message = format({\n value,\n});\nsend(message);',
23
+ ],
24
+ invalid: [
25
+ {
26
+ code: 'await send(\n helper.format({\n value,\n }),\n);',
27
+ errors: [{messageId: 'extractCall', line: 2, column: 2, endLine: 4, endColumn: 4}],
28
+ },
29
+ {
30
+ code: 'send(format<string>(\r\n value,\r\n));',
31
+ errors: [{messageId: 'extractCall'}],
32
+ },
33
+ {
34
+ code: 'send?.(helper.format?.({\n value,\n}));',
35
+ errors: [{messageId: 'extractCall'}],
36
+ },
37
+ ],
38
+ });