@vvedantb/config 0.15.0 → 0.16.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#124](https://github.com/vvedantb/v/pull/124) [`c6b49ed`](https://github.com/vvedantb/v/commit/c6b49eda476dfbe20cffa5c180068fe653357fa2) Thanks [@vvedantb](https://github.com/vvedantb)! - Add the `vvedantb/no-comments` oxlint rule with an autofix. It flags comments other than lint and tool directives, licence headers, JSDoc before an `export`, JSDoc `@type` annotations and comments with an `http(s)://` link, and skips `.d.ts` files and `.claude` and `.agents` folders. The shared `oxlint/base.json` now registers the `vvedantb` plugin and turns the rule on.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#125](https://github.com/vvedantb/v/pull/125) [`c850e4c`](https://github.com/vvedantb/v/commit/c850e4c7a01878d60a7526d5a3d8361a1cd5d01b) Thanks [@vvedantb](https://github.com/vvedantb)! - `vvedantb/no-comments` keeps `@vitest-environment` directives.
12
+
3
13
  ## 0.15.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -57,7 +57,7 @@ The package ships two oxlint JS plugins. Both load with oxlint 1.79 or later (th
57
57
 
58
58
  #### `vvedantb` plugin: `@vvedantb/config/oxlint/plugin.mjs`
59
59
 
60
- Twelve rules, with no app prefix:
60
+ Thirteen rules, with no app prefix:
61
61
 
62
62
  | Rule | Flags |
63
63
  | --- | --- |
@@ -67,6 +67,7 @@ Twelve rules, with no app prefix:
67
67
  | `no-json-parse` | A bare `JSON.parse(...)` result that flows unchecked. `schema.parse(JSON.parse(x))` / `schema.safeParse(...)` are always allowed. With `{ "allowUnknownEscapeHatch": true }`, a `: unknown` annotation or `as unknown` cast is also allowed. |
68
68
  | `no-is-record` | Any identifier named `isRecord`. An `unknown` leaked in; type the data at its entry point instead. |
69
69
  | `no-settings-description` | A `description` prop on `SettingsSection`, `SettingsToggleRow` or `LabeledSwitchRow`. Opt in only where an app wants a hard ban; the default guidance is the `## UI copy` section, which allows a description where the user needs one. `{ "components": ["ProfileCard"] }` adds component names. |
70
+ | `no-comments` | A comment that is not a lint or tool directive, a licence header, JSDoc before an `export`, a JSDoc `@type` annotation or a comment with an `http(s)://` link. `oxlint --fix` removes it. Skips `.d.ts` files and `.claude` and `.agents` folders. |
70
71
  | `no-ts-nocheck` | `@ts-nocheck` and `@ts-ignore` comments. `@ts-expect-error` with a reason stays allowed. |
71
72
  | `no-conditional-tests` | An `expect(...)` call inside an `if`, `?:`, `&&`/`\|\|` or `switch` case in a test file. |
72
73
  | `no-inline-object-type-assertion` | `x as { … }` and `x as Record<string, unknown>`. |
package/oxlint/base.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
3
3
  "plugins": ["typescript", "import", "unicorn", "react"],
4
- "jsPlugins": [{ "name": "no-effect", "specifier": "./no-effect.mjs" }],
4
+ "jsPlugins": [
5
+ { "name": "no-effect", "specifier": "./no-effect.mjs" },
6
+ { "name": "vvedantb", "specifier": "./plugin.mjs" }
7
+ ],
5
8
  "categories": {
6
9
  "suspicious": "error"
7
10
  },
@@ -16,6 +19,8 @@
16
19
  "**/android/**",
17
20
  "**/ios/**",
18
21
  "**/routeTree.gen.ts",
22
+ "**/.claude/**",
23
+ "**/.agents/**",
19
24
  "**/*.d.ts"
20
25
  ],
21
26
  "rules": {
@@ -35,6 +40,7 @@
35
40
  "no-effect/no-pass-data-to-parent": "error",
36
41
  "no-effect/no-external-store-subscription": "error",
37
42
  "no-effect/no-initialize-state": "error",
43
+ "vvedantb/no-comments": "error",
38
44
  "no-console": ["error", { "allow": ["warn", "error", "info"] }],
39
45
  "no-restricted-properties": [
40
46
  "error",
package/oxlint/plugin.mjs CHANGED
@@ -15,11 +15,12 @@
15
15
  // }
16
16
  // }
17
17
  //
18
- // Twelve rules ship; see the package README for the full list.
18
+ // Thirteen rules ship; see the package README for the full list.
19
19
  // oxlint reports each as `vvedantb(<rule>)`.
20
20
 
21
21
  import noDoubleCast from "./rules/no-double-cast.mjs";
22
22
  import noJsonParse from "./rules/no-json-parse.mjs";
23
+ import noComments from "./rules/no-comments.mjs";
23
24
  import noConditionalTests from "./rules/no-conditional-tests.mjs";
24
25
  import noInlineObjectTypeAssertion from "./rules/no-inline-object-type-assertion.mjs";
25
26
  import noInlineZodSchema from "./rules/no-inline-zod-schema.mjs";
@@ -34,6 +35,7 @@ import noValueBlockInTry from "./rules/no-value-block-in-try.mjs";
34
35
  export default {
35
36
  meta: { name: "vvedantb" },
36
37
  rules: {
38
+ "no-comments": noComments,
37
39
  "no-conditional-tests": noConditionalTests,
38
40
  "no-double-cast": noDoubleCast,
39
41
  "no-inline-object-type-assertion": noInlineObjectTypeAssertion,
@@ -0,0 +1,135 @@
1
+ const message =
2
+ "No comments. Say it in code: a clearer name, a type, an extracted function. " +
3
+ "Kept: lint and tool directives, license headers, doc comments on exports, and comments with an issue or RFC link.";
4
+
5
+ const directive =
6
+ /^\s*(?:[*/]\s*)?(?:eslint-(?:disable|enable)|oxlint-(?:disable|enable)|@ts-(?:expect-error|ignore|nocheck|check)|[a-z]+(?:-[a-z]+)*-ignore\b|@vite-ignore|@vitest-environment|webpack[A-Z]|[#@]__(?:PURE|NO_SIDE_EFFECTS)__|@refresh\b|@jsx|<reference\b|(?:istanbul|c8|v8) ignore)/;
7
+ const license = /\b(?:license|copyright|SPDX-License-Identifier)\b/i;
8
+ const link = /https?:\/\//;
9
+ const typeAnnotation = /^\*\s*@(?:type|satisfies)\s*\{/;
10
+
11
+ function isKept(comment, text) {
12
+ const value = comment.value;
13
+ if (directive.test(value) || license.test(value) || link.test(value) || typeAnnotation.test(value)) {
14
+ return true;
15
+ }
16
+ if (comment.type !== "Block" || !value.startsWith("*")) {
17
+ return false;
18
+ }
19
+ return /^\s*export\s/.test(text.slice(comment.range[1]));
20
+ }
21
+
22
+ function lineStart(text, index) {
23
+ return text.lastIndexOf("\n", index - 1) + 1;
24
+ }
25
+
26
+ function lineEnd(text, index) {
27
+ const end = text.indexOf("\n", index);
28
+ return end === -1 ? text.length : end;
29
+ }
30
+
31
+ function isBlank(text, start, end) {
32
+ return text.slice(start, end).trim() === "";
33
+ }
34
+
35
+ function ownsLines(text, range) {
36
+ return (
37
+ isBlank(text, lineStart(text, range[0]), range[0]) &&
38
+ isBlank(text, range[1], lineEnd(text, range[1]))
39
+ );
40
+ }
41
+
42
+ function wholeLineRuns(text, ranges) {
43
+ const runs = new Map();
44
+ let run = null;
45
+ for (const range of ranges) {
46
+ if (!ownsLines(text, range)) {
47
+ run = null;
48
+ continue;
49
+ }
50
+ const start = lineStart(text, range[0]);
51
+ if (run !== null && isBlank(text, run.end, start)) {
52
+ run.end = lineEnd(text, range[1]);
53
+ } else {
54
+ run = { start, end: lineEnd(text, range[1]) };
55
+ }
56
+ runs.set(range, run);
57
+ }
58
+ return runs;
59
+ }
60
+
61
+ function lineRemoval(text, run) {
62
+ const end = Math.min(run.end + 1, text.length);
63
+ const previousLineBlank =
64
+ run.start === 0 || isBlank(text, lineStart(text, run.start - 1), run.start);
65
+ const nextLineEnd = lineEnd(text, end);
66
+ if (previousLineBlank && end < text.length && isBlank(text, end, nextLineEnd)) {
67
+ return [run.start, Math.min(nextLineEnd + 1, text.length)];
68
+ }
69
+ return [run.start, end];
70
+ }
71
+
72
+ function inlineRemoval(text, range) {
73
+ if (isBlank(text, lineStart(text, range[0]), range[0])) {
74
+ let end = range[1];
75
+ while (text[end] === " " || text[end] === "\t") {
76
+ end += 1;
77
+ }
78
+ return [range[0], end];
79
+ }
80
+ let start = range[0];
81
+ while (start > 0 && (text[start - 1] === " " || text[start - 1] === "\t")) {
82
+ start -= 1;
83
+ }
84
+ return [start, range[1]];
85
+ }
86
+
87
+ export default {
88
+ meta: {
89
+ type: "suggestion",
90
+ fixable: "code",
91
+ docs: { description: message },
92
+ },
93
+ create(context) {
94
+ const filename = (context.filename ?? context.getFilename?.() ?? "").replaceAll("\\", "/");
95
+ if (/\.d\.ts$/.test(filename) || /\/\.(?:claude|agents)\//.test(filename)) {
96
+ return {};
97
+ }
98
+ const sourceCode = context.sourceCode;
99
+ const emptyJsxContainers = [];
100
+ return {
101
+ JSXExpressionContainer(node) {
102
+ if (node.expression.type === "JSXEmptyExpression") {
103
+ emptyJsxContainers.push(node.range);
104
+ }
105
+ },
106
+ "Program:exit"() {
107
+ const text = sourceCode.text;
108
+ const targets = [];
109
+ for (const comment of sourceCode.getAllComments()) {
110
+ if (isKept(comment, text)) {
111
+ continue;
112
+ }
113
+ const container = emptyJsxContainers.find(
114
+ (range) => range[0] <= comment.range[0] && comment.range[1] <= range[1],
115
+ );
116
+ targets.push({ comment, range: container ?? comment.range });
117
+ }
118
+ const unique = [...new Map(targets.map((t) => [t.range, t])).values()];
119
+ const runs = wholeLineRuns(
120
+ text,
121
+ unique.map((t) => t.range),
122
+ );
123
+ for (const { comment, range } of targets) {
124
+ const run = runs.get(range);
125
+ const removal = run ? lineRemoval(text, run) : inlineRemoval(text, range);
126
+ context.report({
127
+ loc: comment.loc,
128
+ message,
129
+ fix: (fixer) => fixer.removeRange(removal),
130
+ });
131
+ }
132
+ },
133
+ };
134
+ },
135
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/config",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "license": "MIT",
5
5
  "description": "Shared tsconfig bases, oxlint base, Vite, Vitest, Babel and Metro presets, a WXT preset and host-permission helper for Chrome extensions, pinned tool versions, a sync CLI for Claude commands, CLAUDE.md, Cursor environment and Convex tsconfig, a packaged Electron app.asar module check, a shared header and footer check, a no-source-text-in-tests check, a no-comments check with a ratchet baseline, shared oxlint JS plugins and a CLI that adds an extension to Clerk's allowed origins.",
6
6
  "type": "module",