@abyssalfragments/linter-config 1.4.1 → 1.5.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.mts +5 -2
- package/dist/index.mjs +27 -14
- package/dist/plugins/header.d.mts +3 -0
- package/dist/plugins/header.mjs +163 -0
- package/dist/plugins/lillith.d.mts +9 -0
- package/dist/plugins/lillith.mjs +12 -0
- package/package.json +5 -3
package/dist/index.d.mts
CHANGED
|
@@ -31,6 +31,7 @@ declare function oxfmt(config?: OxfmtConfig): {
|
|
|
31
31
|
sortPackageJson: true;
|
|
32
32
|
sortTailwindcss: true;
|
|
33
33
|
jsdoc: true;
|
|
34
|
+
endOfLine: "lf";
|
|
34
35
|
};
|
|
35
36
|
type OxlintConfig = SharedConfig & {
|
|
36
37
|
license?: {
|
|
@@ -58,6 +59,8 @@ declare function oxlint(config?: OxlintConfig): {
|
|
|
58
59
|
args: "after-used";
|
|
59
60
|
argsIgnorePattern: string;
|
|
60
61
|
}];
|
|
62
|
+
"unicorn/no-empty-file": "off";
|
|
63
|
+
"lillith/no-lambda-i": "error";
|
|
61
64
|
"no-restricted-imports": ["error", {
|
|
62
65
|
paths: {
|
|
63
66
|
name: string;
|
|
@@ -71,10 +74,10 @@ declare function oxlint(config?: OxlintConfig): {
|
|
|
71
74
|
}];
|
|
72
75
|
"header/header"?: ["error", {
|
|
73
76
|
files: string[];
|
|
74
|
-
|
|
77
|
+
allowIndent: boolean;
|
|
75
78
|
} | {
|
|
76
79
|
text: string | string[];
|
|
77
|
-
|
|
80
|
+
allowIndent: boolean;
|
|
78
81
|
}] | undefined;
|
|
79
82
|
};
|
|
80
83
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import header_default from "./plugins/header.mjs";
|
|
1
2
|
import js from "@eslint/js";
|
|
2
3
|
import eslintConfigPrettier from "eslint-config-prettier/flat";
|
|
3
|
-
import header from "eslint-plugin-simple-header";
|
|
4
4
|
import unusedImports from "eslint-plugin-unused-imports";
|
|
5
5
|
import { defineConfig, globalIgnores } from "eslint/config";
|
|
6
6
|
import globals from "globals";
|
|
@@ -32,12 +32,12 @@ const sharedIgnores = [
|
|
|
32
32
|
// src/eslint.ts
|
|
33
33
|
const defaultConfig$2 = Object.freeze({});
|
|
34
34
|
function eslint(config = defaultConfig$2) {
|
|
35
|
-
return defineConfig([globalIgnores([...config.extraIgnores ? config.extraIgnores : [], ...sharedIgnores.map((
|
|
35
|
+
return defineConfig([globalIgnores([...config.extraIgnores ? config.extraIgnores : [], ...sharedIgnores.map((ignore) => `${ignore}/*`)]), {
|
|
36
36
|
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
|
|
37
37
|
plugins: {
|
|
38
38
|
js,
|
|
39
39
|
"unused-imports": unusedImports,
|
|
40
|
-
header
|
|
40
|
+
header: header_default
|
|
41
41
|
},
|
|
42
42
|
extends: [
|
|
43
43
|
js.configs.recommended,
|
|
@@ -78,7 +78,7 @@ function eslint(config = defaultConfig$2) {
|
|
|
78
78
|
const defaultConfig$1 = Object.freeze({});
|
|
79
79
|
function oxfmt(config = defaultConfig$1) {
|
|
80
80
|
return defineConfig$1({
|
|
81
|
-
ignorePatterns: [...config.extraIgnores ? config.extraIgnores : [], ...sharedIgnores.map((
|
|
81
|
+
ignorePatterns: [...config.extraIgnores ? config.extraIgnores : [], ...sharedIgnores.map((ignore) => `${ignore}/**/*`)],
|
|
82
82
|
tabWidth: config.rumiMode ? 4 : 2,
|
|
83
83
|
useTabs: config.rumiMode,
|
|
84
84
|
astro: true,
|
|
@@ -86,27 +86,38 @@ function oxfmt(config = defaultConfig$1) {
|
|
|
86
86
|
sortImports: true,
|
|
87
87
|
sortPackageJson: true,
|
|
88
88
|
sortTailwindcss: true,
|
|
89
|
-
jsdoc: true
|
|
89
|
+
jsdoc: true,
|
|
90
|
+
endOfLine: "lf"
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
93
|
// src/oxlint.ts
|
|
93
94
|
const defaultConfig = Object.freeze({});
|
|
94
95
|
function oxlint(config = defaultConfig) {
|
|
95
96
|
return defineConfig$2({
|
|
96
|
-
ignorePatterns: [...config.extraIgnores ? config.extraIgnores : [], ...sharedIgnores.map((
|
|
97
|
-
jsPlugins: [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
ignorePatterns: [...config.extraIgnores ? config.extraIgnores : [], ...sharedIgnores.map((ignore) => `${ignore}/*`)],
|
|
98
|
+
jsPlugins: [
|
|
99
|
+
{
|
|
100
|
+
name: "eslint-js",
|
|
101
|
+
specifier: "oxlint-plugin-eslint"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: "lillith",
|
|
105
|
+
specifier: "@abyssalfragments/linter-config/plugins/lillith"
|
|
106
|
+
},
|
|
107
|
+
config.license ? {
|
|
108
|
+
name: "header",
|
|
109
|
+
specifier: "@abyssalfragments/linter-config/plugins/header"
|
|
110
|
+
} : null
|
|
111
|
+
].filter((plugin) => plugin !== null),
|
|
104
112
|
env: config.env ?? {
|
|
105
113
|
node: true,
|
|
106
114
|
es6: true
|
|
107
115
|
},
|
|
108
116
|
rules: {
|
|
109
|
-
...config.license ? { "header/header": ["error",
|
|
117
|
+
...config.license ? { "header/header": ["error", {
|
|
118
|
+
allowIndent: true,
|
|
119
|
+
..."file" in config.license ? { files: [config.license.file] } : { text: "shared" in config.license ? Licenses[config.license.shared] : config.license.text }
|
|
120
|
+
}] } : {},
|
|
110
121
|
"no-undef": "off",
|
|
111
122
|
"no-redeclare": "error",
|
|
112
123
|
"no-unused-vars": ["warn", {
|
|
@@ -115,6 +126,8 @@ function oxlint(config = defaultConfig) {
|
|
|
115
126
|
args: "after-used",
|
|
116
127
|
argsIgnorePattern: "^_"
|
|
117
128
|
}],
|
|
129
|
+
"unicorn/no-empty-file": "off",
|
|
130
|
+
"lillith/no-lambda-i": "error",
|
|
118
131
|
"no-restricted-imports": ["error", { paths: [{
|
|
119
132
|
name: "discord.js",
|
|
120
133
|
importNames: ["Colors"],
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
// src/plugins/header.ts
|
|
3
|
+
const mapLines = (text, f) => text.split("\n").map(f).join("\n");
|
|
4
|
+
const escapeRegex = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
|
+
function isComment(text, syntax) {
|
|
6
|
+
if (Array.isArray(syntax)) return text.startsWith(syntax[0]) && text.endsWith(syntax[1]);
|
|
7
|
+
return text.split("\n").every((x) => x.startsWith(syntax));
|
|
8
|
+
}
|
|
9
|
+
function makeComment(text, syntax, decor) {
|
|
10
|
+
if (isComment(text, syntax)) return text;
|
|
11
|
+
if (Array.isArray(syntax)) return syntax[0] + decor[0] + mapLines(text, (x) => (decor[1] + x).trimEnd()) + decor[2] + syntax[1];
|
|
12
|
+
return mapLines(text, (x) => (syntax + decor + x).trimEnd());
|
|
13
|
+
}
|
|
14
|
+
function matchHeader(srcHeader, headers, templates) {
|
|
15
|
+
for (const header of headers) {
|
|
16
|
+
const body = escapeRegex(header).replace(/\\\{(\w+)\\\}/g, (m, key) => templates[key]?.[0] ?? m);
|
|
17
|
+
if (new RegExp(`^${body}$`).test(srcHeader)) return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function makeHeader(headers, templates) {
|
|
22
|
+
return headers[0].replace(/\{(\w+)\}/g, (m, key) => templates[key]?.[1] ?? m);
|
|
23
|
+
}
|
|
24
|
+
function stripExclamations(header, syntax) {
|
|
25
|
+
if (Array.isArray(syntax)) {
|
|
26
|
+
if (header.startsWith(syntax[0] + "!")) return syntax[0] + header.slice(syntax[0].length + 1);
|
|
27
|
+
return header;
|
|
28
|
+
}
|
|
29
|
+
return mapLines(header, (x) => x.startsWith(syntax + "!") ? syntax + x.slice(syntax.length + 1) : x);
|
|
30
|
+
}
|
|
31
|
+
function findHeader(src, syntax, allowIndent) {
|
|
32
|
+
let pat;
|
|
33
|
+
if (Array.isArray(syntax)) pat = String.raw`^\s*(${escapeRegex(syntax[0])}.*?${escapeRegex(syntax[1])}(?:[ \t]*\r?\n)*)?`;
|
|
34
|
+
else pat = String.raw`^\s*(${allowIndent ? "[ \\t]*" : ""}${escapeRegex(syntax)}[^\n]*\r?\n)*(?:[ \t]*\r?\n)*`;
|
|
35
|
+
const match = new RegExp(pat, "s").exec(src)?.[0] ?? "";
|
|
36
|
+
if ((allowIndent ? match.trimStart() : match).startsWith("/**")) return "";
|
|
37
|
+
return match;
|
|
38
|
+
}
|
|
39
|
+
function stripIndent(header, allowIndent) {
|
|
40
|
+
const firstLine = header.search(/\S/);
|
|
41
|
+
const indent = firstLine < 0 ? "" : header.slice(0, firstLine).match(/[ \t]*$/)?.[0] ?? "";
|
|
42
|
+
const trimmed = header.trim();
|
|
43
|
+
if (!allowIndent || !indent) return trimmed;
|
|
44
|
+
const lines = trimmed.split("\n");
|
|
45
|
+
if (!lines.slice(1).every((line) => line.startsWith(indent))) return trimmed;
|
|
46
|
+
return lines.map((line, index) => index === 0 ? line : line.slice(indent.length)).join("\n");
|
|
47
|
+
}
|
|
48
|
+
var header_default = {
|
|
49
|
+
meta: { name: "@abyssalfragments/linter-config/plugins/header" },
|
|
50
|
+
rules: { header: {
|
|
51
|
+
meta: {
|
|
52
|
+
type: "layout",
|
|
53
|
+
fixable: "code",
|
|
54
|
+
schema: [{
|
|
55
|
+
type: "object",
|
|
56
|
+
additionalProperties: false,
|
|
57
|
+
allOf: [{ anyOf: [{ properties: {
|
|
58
|
+
syntax: { type: "string" },
|
|
59
|
+
decor: { type: "string" }
|
|
60
|
+
} }, { properties: {
|
|
61
|
+
syntax: {
|
|
62
|
+
type: "array",
|
|
63
|
+
items: { type: "string" },
|
|
64
|
+
minItems: 2,
|
|
65
|
+
maxItems: 2
|
|
66
|
+
},
|
|
67
|
+
decor: {
|
|
68
|
+
type: "array",
|
|
69
|
+
items: { type: "string" },
|
|
70
|
+
minItems: 3,
|
|
71
|
+
maxItems: 3
|
|
72
|
+
}
|
|
73
|
+
} }] }, { oneOf: [{
|
|
74
|
+
required: ["files"],
|
|
75
|
+
properties: { files: {
|
|
76
|
+
type: "array",
|
|
77
|
+
items: { type: "string" },
|
|
78
|
+
minItems: 1
|
|
79
|
+
} }
|
|
80
|
+
}, {
|
|
81
|
+
required: ["text"],
|
|
82
|
+
properties: { text: { oneOf: [{ type: "string" }, {
|
|
83
|
+
type: "array",
|
|
84
|
+
items: { type: "string" }
|
|
85
|
+
}] } }
|
|
86
|
+
}] }],
|
|
87
|
+
properties: {
|
|
88
|
+
syntax: {},
|
|
89
|
+
decor: {},
|
|
90
|
+
files: {},
|
|
91
|
+
text: {},
|
|
92
|
+
templates: {
|
|
93
|
+
type: "object",
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
patternProperties: { "^\\w+$": {
|
|
96
|
+
type: "array",
|
|
97
|
+
items: { type: "string" },
|
|
98
|
+
minItems: 2,
|
|
99
|
+
maxItems: 2
|
|
100
|
+
} }
|
|
101
|
+
},
|
|
102
|
+
newlines: {
|
|
103
|
+
type: "number",
|
|
104
|
+
minimum: 0
|
|
105
|
+
},
|
|
106
|
+
allowIndent: { type: "boolean" },
|
|
107
|
+
linebreak: {
|
|
108
|
+
type: "string",
|
|
109
|
+
pattern: "^(unix|windows)$"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}]
|
|
113
|
+
},
|
|
114
|
+
create(ctx) {
|
|
115
|
+
const options = ctx.options[0];
|
|
116
|
+
const syntax = options.syntax ?? ["/*", "*/"];
|
|
117
|
+
const decor = options.decor ?? (Array.isArray(syntax) ? [
|
|
118
|
+
"\n",
|
|
119
|
+
" * ",
|
|
120
|
+
"\n "
|
|
121
|
+
] : " ");
|
|
122
|
+
const templates = {
|
|
123
|
+
year: ["\\d{4}", `${(/* @__PURE__ */ new Date()).getFullYear()}`],
|
|
124
|
+
...options.templates
|
|
125
|
+
};
|
|
126
|
+
const newlines = options.newlines ?? 1;
|
|
127
|
+
const allowIndent = options.allowIndent ?? false;
|
|
128
|
+
const rawHeaders = options.files ? options.files.map((f) => readFileSync(f, "utf8").trim()) : [Array.isArray(options.text) ? options.text.join("\n") : options.text];
|
|
129
|
+
const src = "text" in ctx.sourceCode ? ctx.sourceCode.text : null;
|
|
130
|
+
if (!src) return {};
|
|
131
|
+
const endl = options.linebreak ? options.linebreak === "windows" ? "\r\n" : "\n" : src.includes("\r\n") ? "\r\n" : "\n";
|
|
132
|
+
const offset = src.match(/^#!.*?\n/)?.[0]?.length ?? 0;
|
|
133
|
+
if (/^\s*\/\/ header-disable(?:\r?\n|$)/.test(src.slice(offset))) return {};
|
|
134
|
+
const srcHeader = findHeader(src.slice(offset), syntax, allowIndent);
|
|
135
|
+
const headers = rawHeaders.map((raw) => makeComment(raw, syntax, decor).replace(/\n/g, endl));
|
|
136
|
+
const trailingLines = endl.repeat(src.slice(srcHeader.length).trim() ? 1 + newlines : 1);
|
|
137
|
+
if (!matchHeader(stripExclamations(stripIndent(srcHeader, allowIndent), syntax), headers, templates)) ctx.report({
|
|
138
|
+
message: srcHeader.trim() ? "Invalid header" : "Missing header",
|
|
139
|
+
loc: {
|
|
140
|
+
line: 1,
|
|
141
|
+
column: 0
|
|
142
|
+
},
|
|
143
|
+
fix(fixer) {
|
|
144
|
+
const header = makeHeader(headers, templates) + trailingLines;
|
|
145
|
+
return fixer.replaceTextRange([offset, offset + srcHeader.length], header);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
else if (!stripIndent(srcHeader, allowIndent).startsWith(syntax[0]) || /(\r?\n)*$/.exec(srcHeader)?.[0] !== trailingLines) ctx.report({
|
|
149
|
+
message: "Bad header spacing",
|
|
150
|
+
loc: {
|
|
151
|
+
line: 1,
|
|
152
|
+
column: 0
|
|
153
|
+
},
|
|
154
|
+
fix(fixer) {
|
|
155
|
+
const header = (allowIndent ? srcHeader.match(/^[ \t]*/)?.[0] ?? "" : "") + srcHeader.trim() + trailingLines;
|
|
156
|
+
return fixer.replaceTextRange([offset, offset + srcHeader.length], header);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
} }
|
|
162
|
+
};
|
|
163
|
+
export { header_default as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var lillith_default = {
|
|
2
|
+
meta: { name: "lillith" },
|
|
3
|
+
rules: { "no-lambda-i": { create(context) {
|
|
4
|
+
return { ArrowFunctionExpression(node) {
|
|
5
|
+
if (node.params.some((param) => param.name === "i")) context.report({
|
|
6
|
+
message: "No naming lambda variables 'i'",
|
|
7
|
+
node
|
|
8
|
+
});
|
|
9
|
+
} };
|
|
10
|
+
} } }
|
|
11
|
+
};
|
|
12
|
+
export { lillith_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abyssalfragments/linter-config",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Abyssal Fragments shared linter config (eslint, prettier, etc)",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://git.abyssalfragments.org/packages/linter-config/issues"
|
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": "./dist/index.mjs",
|
|
23
|
+
"./plugins/header": "./dist/plugins/header.mjs",
|
|
24
|
+
"./plugins/lillith": "./dist/plugins/lillith.mjs",
|
|
23
25
|
"./package.json": "./package.json"
|
|
24
26
|
},
|
|
25
27
|
"scripts": {
|
|
26
28
|
"build": "tsdown",
|
|
27
|
-
"dev": "tsdown --watch",
|
|
29
|
+
"dev": "tsdown --watch --sourcemap",
|
|
28
30
|
"check": "tsc --noEmit",
|
|
29
31
|
"prepublishOnly": "npm run build",
|
|
30
32
|
"lint": "oxlint . && oxfmt --check",
|
|
@@ -34,8 +36,8 @@
|
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
38
|
"@eslint/js": "10.0.1",
|
|
39
|
+
"@oxlint/plugins": "^1.93.0",
|
|
37
40
|
"eslint-config-prettier": "^10.1.8",
|
|
38
|
-
"eslint-plugin-simple-header": "1.2.2",
|
|
39
41
|
"eslint-plugin-unused-imports": "4.4.1",
|
|
40
42
|
"globals": "17.14.0",
|
|
41
43
|
"oxlint-plugin-eslint": "^1.93.0",
|