@abyssalfragments/linter-config 1.4.1 → 1.4.2

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 CHANGED
@@ -58,6 +58,7 @@ declare function oxlint(config?: OxlintConfig): {
58
58
  args: "after-used";
59
59
  argsIgnorePattern: string;
60
60
  }];
61
+ "unicorn/no-empty-file": "off";
61
62
  "no-restricted-imports": ["error", {
62
63
  paths: {
63
64
  name: string;
@@ -71,10 +72,10 @@ declare function oxlint(config?: OxlintConfig): {
71
72
  }];
72
73
  "header/header"?: ["error", {
73
74
  files: string[];
74
- text?: undefined;
75
+ allowIndent: boolean;
75
76
  } | {
76
77
  text: string | string[];
77
- files?: undefined;
78
+ allowIndent: boolean;
78
79
  }] | undefined;
79
80
  };
80
81
  };
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";
@@ -37,7 +37,7 @@ function eslint(config = defaultConfig$2) {
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,
@@ -99,14 +99,17 @@ function oxlint(config = defaultConfig) {
99
99
  specifier: "oxlint-plugin-eslint"
100
100
  }, config.license ? {
101
101
  name: "header",
102
- specifier: "eslint-plugin-simple-header"
102
+ specifier: "@abyssalfragments/linter-config/plugins/header"
103
103
  } : null].filter((i) => i !== null),
104
104
  env: config.env ?? {
105
105
  node: true,
106
106
  es6: true
107
107
  },
108
108
  rules: {
109
- ...config.license ? { "header/header": ["error", "file" in config.license ? { files: [config.license.file] } : { text: "shared" in config.license ? Licenses[config.license.shared] : config.license.text }] } : {},
109
+ ...config.license ? { "header/header": ["error", {
110
+ allowIndent: true,
111
+ ..."file" in config.license ? { files: [config.license.file] } : { text: "shared" in config.license ? Licenses[config.license.shared] : config.license.text }
112
+ }] } : {},
110
113
  "no-undef": "off",
111
114
  "no-redeclare": "error",
112
115
  "no-unused-vars": ["warn", {
@@ -115,6 +118,7 @@ function oxlint(config = defaultConfig) {
115
118
  args: "after-used",
116
119
  argsIgnorePattern: "^_"
117
120
  }],
121
+ "unicorn/no-empty-file": "off",
118
122
  "no-restricted-imports": ["error", { paths: [{
119
123
  name: "discord.js",
120
124
  importNames: ["Colors"],
@@ -0,0 +1,3 @@
1
+ import { ESLint } from "eslint";
2
+ declare const _default: ESLint.Plugin;
3
+ export { _default as default };
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abyssalfragments/linter-config",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
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,6 +20,7 @@
20
20
  "type": "module",
21
21
  "exports": {
22
22
  ".": "./dist/index.mjs",
23
+ "./plugins/header": "./dist/plugins/header.mjs",
23
24
  "./package.json": "./package.json"
24
25
  },
25
26
  "scripts": {
@@ -34,8 +35,8 @@
34
35
  },
35
36
  "dependencies": {
36
37
  "@eslint/js": "10.0.1",
38
+ "@oxlint/plugins": "^1.93.0",
37
39
  "eslint-config-prettier": "^10.1.8",
38
- "eslint-plugin-simple-header": "1.2.2",
39
40
  "eslint-plugin-unused-imports": "4.4.1",
40
41
  "globals": "17.14.0",
41
42
  "oxlint-plugin-eslint": "^1.93.0",