@soujvnunes/eslint-config 0.5.1 → 0.6.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/dist/index.d.ts +13 -10
- package/dist/index.js +114 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import { Linter } from 'eslint';
|
|
1
|
+
import { Rule, Linter } from 'eslint';
|
|
2
|
+
|
|
3
|
+
declare const oneLineComments: Rule.RuleModule;
|
|
4
|
+
declare const oneLineCommentsPlugin: {
|
|
5
|
+
meta: {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
rules: {
|
|
9
|
+
'one-line-comments': Rule.RuleModule;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
2
12
|
|
|
3
13
|
interface ConfigOptions {
|
|
4
14
|
/** Extra ignore globs, merged after the defaults. */
|
|
@@ -7,14 +17,7 @@ interface ConfigOptions {
|
|
|
7
17
|
importGroups?: (string | string[])[];
|
|
8
18
|
/** Root for typescript-eslint's project service. Defaults to cwd. */
|
|
9
19
|
tsconfigRootDir?: string;
|
|
10
|
-
/**
|
|
11
|
-
* Path to the Tailwind v4 CSS entry (the file with `@import "tailwindcss"` + `@theme`, e.g.
|
|
12
|
-
* `./app/tailwind.config.css`). When set on the Next preset, it wires the bundled
|
|
13
|
-
* `eslint-plugin-better-tailwindcss` correctness rules, chiefly `no-unknown-classes`, which flags a
|
|
14
|
-
* class not registered in the theme (a dead token `tsc`/build cannot see; see DESIGN-TOKENS). Leave it
|
|
15
|
-
* unset and the plugin stays off, since without the entry the rule cannot resolve the theme and would
|
|
16
|
-
* flag every class.
|
|
17
|
-
*/
|
|
20
|
+
/** Path to the Tailwind v4 CSS entry (the file with `@import "tailwindcss"` + `@theme`, e.g. `./app/tailwind.config.css`). When set on the Next preset, it wires the bundled `eslint-plugin-better-tailwindcss` correctness rules, chiefly `no-unknown-classes`, which flags a class not registered in the theme (a dead token `tsc`/build cannot see; see DESIGN-TOKENS). Leave it unset and the plugin stays off, since without the entry the rule cannot resolve the theme and would flag every class. */
|
|
18
21
|
tailwindEntryPoint?: string;
|
|
19
22
|
/** Extra flat-config objects appended at the end. */
|
|
20
23
|
extend?: Linter.Config[];
|
|
@@ -24,4 +27,4 @@ declare const createBaseConfig: (options?: ConfigOptions) => any[];
|
|
|
24
27
|
/** Full config for Next.js apps: base plus React, React Hooks, jsx-a11y and Next plugins. */
|
|
25
28
|
declare const createNextConfig: (options?: ConfigOptions) => any[];
|
|
26
29
|
|
|
27
|
-
export { type ConfigOptions, createBaseConfig, createNextConfig };
|
|
30
|
+
export { type ConfigOptions, createBaseConfig, createNextConfig, oneLineComments, oneLineCommentsPlugin };
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,111 @@ import security from "eslint-plugin-security";
|
|
|
13
13
|
import unusedImports from "eslint-plugin-unused-imports";
|
|
14
14
|
import globals from "globals";
|
|
15
15
|
import tseslint from "typescript-eslint";
|
|
16
|
+
|
|
17
|
+
// oneLineComments.ts
|
|
18
|
+
var DIRECTIVE = /^\s*(?:eslint-disable\b|eslint-enable\b|@ts-expect-error|@ts-ignore|@ts-nocheck|@ts-check\b|\/\s*<reference|prettier-ignore|biome-ignore|(?:istanbul|c8|v8|node:coverage)\s+ignore\b|@jsx\b|@jsxImportSource\b|@jsxRuntime\b|@vitest-environment\b|vitest-environment\b|@vite-ignore\b|webpack[A-Z]|@license\b|@preserve\b|@__PURE__|#__PURE__|#__NO_SIDE_EFFECTS__|sourceMappingURL=|sourceURL=)/u;
|
|
19
|
+
var BLOCK_DIRECTIVE = /^\s*(?:eslint\s|eslint-env\b|global\s|globals\s|exported\s)/u;
|
|
20
|
+
var isComment = (comment) => comment.type === "Line" || comment.type === "Block";
|
|
21
|
+
var isDirective = (comment) => DIRECTIVE.test(comment.value) || comment.type === "Block" && BLOCK_DIRECTIVE.test(comment.value);
|
|
22
|
+
var spansLines = (comment) => (comment.loc?.start.line ?? 0) !== (comment.loc?.end.line ?? 0);
|
|
23
|
+
var isOneLine = (text) => !/[\r\n\u2028\u2029]/u.test(text);
|
|
24
|
+
var collapse = (text) => text.replace(/\s+/gu, " ").trim();
|
|
25
|
+
var enclosingJsxComment = (sourceCode, comment) => {
|
|
26
|
+
if (comment.type !== "Block") return null;
|
|
27
|
+
const node = sourceCode.getNodeByRangeIndex(comment.range?.[0] ?? 0);
|
|
28
|
+
return node?.type === "JSXEmptyExpression" ? node.parent ?? null : null;
|
|
29
|
+
};
|
|
30
|
+
var isOwnLine = (sourceCode, comment) => {
|
|
31
|
+
const container = enclosingJsxComment(sourceCode, comment);
|
|
32
|
+
const span = container?.loc ?? comment.loc;
|
|
33
|
+
if (!span) return false;
|
|
34
|
+
const lines = sourceCode.getLines();
|
|
35
|
+
const before = (lines[span.start.line - 1] ?? "").slice(0, span.start.column);
|
|
36
|
+
const after = (lines[span.end.line - 1] ?? "").slice(span.end.column);
|
|
37
|
+
return before.trim() === "" && after.trim() === "";
|
|
38
|
+
};
|
|
39
|
+
var breaksSemicolonInsertion = (sourceCode, comment) => {
|
|
40
|
+
const before = sourceCode.getTokenBefore(comment, { includeComments: true });
|
|
41
|
+
const after = sourceCode.getTokenAfter(comment, { includeComments: true });
|
|
42
|
+
if (!before?.loc || !after?.loc) return false;
|
|
43
|
+
return before.loc.end.line === (comment.loc?.start.line ?? 0) && after.loc.start.line === (comment.loc?.end.line ?? 0);
|
|
44
|
+
};
|
|
45
|
+
var collapsedBlock = (sourceCode, comment) => {
|
|
46
|
+
const raw = sourceCode.getText(comment);
|
|
47
|
+
const open = raw.startsWith("/**") || raw.startsWith("/*!") ? raw.slice(0, 3) : "/*";
|
|
48
|
+
const body = collapse(
|
|
49
|
+
raw.slice(open.length, -2).split(/\r\n|[\r\n\u2028\u2029]/u).map((line) => line.trim().replace(/^\*+ ?/u, "")).filter(Boolean).join(" ")
|
|
50
|
+
);
|
|
51
|
+
const text = body ? `${open} ${body} */` : `${open} */`;
|
|
52
|
+
return isOneLine(text) && text.indexOf("*/") === text.length - 2 ? text : null;
|
|
53
|
+
};
|
|
54
|
+
var oneLineComments = {
|
|
55
|
+
meta: {
|
|
56
|
+
type: "layout",
|
|
57
|
+
docs: { description: "Require a comment to occupy exactly one line, however long it runs." },
|
|
58
|
+
fixable: "code",
|
|
59
|
+
schema: [],
|
|
60
|
+
messages: {
|
|
61
|
+
adjacent: "Two comment lines are touching, and a bare `//` between them does not make them two comments. A comment is one line, however long it runs: join them, or move the rationale to the README or the project MANIFEST.",
|
|
62
|
+
block: "This block comment spans lines. A comment is one line, however long it runs: collapse it, or move the rationale to the README or the project MANIFEST."
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
create(context) {
|
|
66
|
+
const sourceCode = context.sourceCode;
|
|
67
|
+
const comments = sourceCode.getAllComments().filter(isComment);
|
|
68
|
+
return {
|
|
69
|
+
"Program:exit"() {
|
|
70
|
+
for (const comment of comments) {
|
|
71
|
+
if (!spansLines(comment) || isDirective(comment)) continue;
|
|
72
|
+
const text = collapsedBlock(sourceCode, comment);
|
|
73
|
+
const risky = breaksSemicolonInsertion(sourceCode, comment);
|
|
74
|
+
context.report({
|
|
75
|
+
loc: comment.loc,
|
|
76
|
+
messageId: "block",
|
|
77
|
+
fix: text && !risky ? (fixer) => fixer.replaceText(comment, text) : null
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const joinable = comments.filter(
|
|
81
|
+
(comment) => !spansLines(comment) && isOwnLine(sourceCode, comment)
|
|
82
|
+
);
|
|
83
|
+
let run = [];
|
|
84
|
+
const flush = () => {
|
|
85
|
+
const current = run;
|
|
86
|
+
run = [];
|
|
87
|
+
if (current.length < 2) return;
|
|
88
|
+
if (current.some(isDirective)) return;
|
|
89
|
+
const jsx = current.some((comment) => enclosingJsxComment(sourceCode, comment));
|
|
90
|
+
const block = current.some((comment) => comment.type === "Block");
|
|
91
|
+
const body = collapse(current.map((comment) => comment.value.trim()).join(" "));
|
|
92
|
+
const text = `// ${body}`;
|
|
93
|
+
const first = current[0];
|
|
94
|
+
const last = current[current.length - 1];
|
|
95
|
+
if (!first?.loc || !last?.loc) return;
|
|
96
|
+
context.report({
|
|
97
|
+
loc: { start: first.loc.start, end: last.loc.end },
|
|
98
|
+
messageId: "adjacent",
|
|
99
|
+
// A JSX run reports without a fix: merging `{/* a */}` with `{/* b */}` means editing sibling containers, and raw range surgery there can swallow a value-bearing expression.
|
|
100
|
+
fix: jsx || block || !body || !isOneLine(text) ? null : (fixer) => fixer.replaceTextRange([first.range?.[0] ?? 0, last.range?.[1] ?? 0], text)
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
for (const comment of joinable) {
|
|
104
|
+
const previous = run[run.length - 1];
|
|
105
|
+
const touching = previous && (previous.loc?.end.line ?? 0) + 1 === (comment.loc?.start.line ?? 0);
|
|
106
|
+
if (!touching) flush();
|
|
107
|
+
run.push(comment);
|
|
108
|
+
}
|
|
109
|
+
flush();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var oneLineCommentsPlugin = {
|
|
115
|
+
// No `version`: it feeds ESLint's cache key, and a hardcoded one drifts from package.json and serves stale cached results after a behaviour change.
|
|
116
|
+
meta: { name: "@soujvnunes/eslint-config" },
|
|
117
|
+
rules: { "one-line-comments": oneLineComments }
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// index.ts
|
|
16
121
|
var DEFAULT_IGNORES = [
|
|
17
122
|
"**/node_modules/**",
|
|
18
123
|
"**/.next/**",
|
|
@@ -224,6 +329,11 @@ var buildConfig = ({
|
|
|
224
329
|
],
|
|
225
330
|
rules: { "import-x/no-default-export": "off", "no-restricted-syntax": "off" }
|
|
226
331
|
};
|
|
332
|
+
const oneLineCommentsOverride = {
|
|
333
|
+
files: ["**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"],
|
|
334
|
+
plugins: { soujvnunes: oneLineCommentsPlugin },
|
|
335
|
+
rules: { "soujvnunes/one-line-comments": "error" }
|
|
336
|
+
};
|
|
227
337
|
const scriptsOverride = {
|
|
228
338
|
files: ["scripts/**/*.mjs"],
|
|
229
339
|
languageOptions: { globals: { ...globals.node } },
|
|
@@ -252,6 +362,7 @@ var buildConfig = ({
|
|
|
252
362
|
rules
|
|
253
363
|
},
|
|
254
364
|
prettier,
|
|
365
|
+
oneLineCommentsOverride,
|
|
255
366
|
rootConfigOverride,
|
|
256
367
|
...next ? [nextFileConventionsOverride] : [],
|
|
257
368
|
scriptsOverride,
|
|
@@ -262,5 +373,7 @@ var createBaseConfig = (options) => buildConfig({ ...options, next: false });
|
|
|
262
373
|
var createNextConfig = (options) => buildConfig({ ...options, next: true });
|
|
263
374
|
export {
|
|
264
375
|
createBaseConfig,
|
|
265
|
-
createNextConfig
|
|
376
|
+
createNextConfig,
|
|
377
|
+
oneLineComments,
|
|
378
|
+
oneLineCommentsPlugin
|
|
266
379
|
};
|