@thethracian/oxlint-config 0.1.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.
Files changed (59) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +17 -0
  3. package/dist/index.d.ts +86 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +84 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/rules/acronym-case.d.ts +5 -0
  8. package/dist/rules/acronym-case.d.ts.map +1 -0
  9. package/dist/rules/acronym-case.js +205 -0
  10. package/dist/rules/acronym-case.js.map +1 -0
  11. package/dist/rules/acronyms.d.ts +10 -0
  12. package/dist/rules/acronyms.d.ts.map +1 -0
  13. package/dist/rules/acronyms.js +1582 -0
  14. package/dist/rules/acronyms.js.map +1 -0
  15. package/dist/rules/boolean-prefix.d.ts +6 -0
  16. package/dist/rules/boolean-prefix.d.ts.map +1 -0
  17. package/dist/rules/boolean-prefix.js +96 -0
  18. package/dist/rules/boolean-prefix.js.map +1 -0
  19. package/dist/rules/camel-case-identifiers.d.ts +14 -0
  20. package/dist/rules/camel-case-identifiers.d.ts.map +1 -0
  21. package/dist/rules/camel-case-identifiers.js +68 -0
  22. package/dist/rules/camel-case-identifiers.js.map +1 -0
  23. package/dist/rules/char-class.d.ts +18 -0
  24. package/dist/rules/char-class.d.ts.map +1 -0
  25. package/dist/rules/char-class.js +29 -0
  26. package/dist/rules/char-class.js.map +1 -0
  27. package/dist/rules/max-import-depth.d.ts +6 -0
  28. package/dist/rules/max-import-depth.d.ts.map +1 -0
  29. package/dist/rules/max-import-depth.js +29 -0
  30. package/dist/rules/max-import-depth.js.map +1 -0
  31. package/dist/rules/max-line-length.d.ts +7 -0
  32. package/dist/rules/max-line-length.d.ts.map +1 -0
  33. package/dist/rules/max-line-length.js +15 -0
  34. package/dist/rules/max-line-length.js.map +1 -0
  35. package/dist/rules/no-commented-out-code.d.ts +12 -0
  36. package/dist/rules/no-commented-out-code.d.ts.map +1 -0
  37. package/dist/rules/no-commented-out-code.js +181 -0
  38. package/dist/rules/no-commented-out-code.js.map +1 -0
  39. package/dist/rules/pascal-case-types.d.ts +9 -0
  40. package/dist/rules/pascal-case-types.d.ts.map +1 -0
  41. package/dist/rules/pascal-case-types.js +74 -0
  42. package/dist/rules/pascal-case-types.js.map +1 -0
  43. package/dist/rules/plugin.d.ts +122 -0
  44. package/dist/rules/plugin.d.ts.map +1 -0
  45. package/dist/rules/plugin.js +373 -0
  46. package/dist/rules/plugin.js.map +1 -0
  47. package/dist/rules/private-underscore.d.ts +9 -0
  48. package/dist/rules/private-underscore.d.ts.map +1 -0
  49. package/dist/rules/private-underscore.js +13 -0
  50. package/dist/rules/private-underscore.js.map +1 -0
  51. package/dist/rules/require-file-doc.d.ts +12 -0
  52. package/dist/rules/require-file-doc.d.ts.map +1 -0
  53. package/dist/rules/require-file-doc.js +105 -0
  54. package/dist/rules/require-file-doc.js.map +1 -0
  55. package/dist/rules/require-function-doc.d.ts +23 -0
  56. package/dist/rules/require-function-doc.d.ts.map +1 -0
  57. package/dist/rules/require-function-doc.js +268 -0
  58. package/dist/rules/require-function-doc.js.map +1 -0
  59. package/package.json +33 -0
package/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Thracian
4
+
5
+ See the repository LICENSE file for the full license text.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @thethracian/oxlint-config
2
+
3
+ Importable Oxlint config for TypeScript projects.
4
+
5
+ The config errors on lines over 150 characters, files over 500 lines, functions over 75 lines, nesting deeper than 3 levels, callback nesting deeper than 4 levels (max-nested-callbacks), more than 5 parameters, cyclomatic complexity over 10, requires strict equality (eqeqeq), denies eval and dynamic code execution (no-eval, no-implied-eval when type-aware), denies debug artifacts (no-console, no-debugger), bans silent catch blocks (no-empty), bans commented-out code (custom thethracian/no-commented-out-code rule), bans inline comments and warning comments (no-inline-comments, no-warning-comments), bans `any` and untyped escape hatches (no-explicit-any, no-unsafe-call, no-unsafe-member-access, plus no-unsafe-assignment/return/argument when type-aware), denies unhandled promises (no-floating-promises, no-misused-promises when type-aware), and enforces immutability with prefer-const and no-param-reassign (including property mutations).
6
+
7
+ Requires `oxlint-plugin-complexity` (peer dependency) for the cyclomatic complexity rule.
8
+
9
+ ```sh
10
+ pnpm add -D @thethracian/oxlint-config oxlint@^1.63.0 oxlint-tsgolint@^0.22.1 oxlint-plugin-complexity
11
+ ```
12
+
13
+ ```ts
14
+ import theThracian from '@thethracian/oxlint-config';
15
+
16
+ export default theThracian();
17
+ ```
@@ -0,0 +1,86 @@
1
+ export type TheThracianOxlintOptions = {
2
+ typeAware?: boolean;
3
+ };
4
+ export default function theThracianOxlint(options?: TheThracianOxlintOptions): {
5
+ categories: {
6
+ correctness: "error";
7
+ suspicious: "error";
8
+ perf: "error";
9
+ style: "error";
10
+ };
11
+ plugins: ("unicorn" | "typescript" | "oxc" | "import" | "promise")[];
12
+ jsPlugins: string[];
13
+ rules: {
14
+ 'complexity/complexity': ["error", {
15
+ cyclomatic: number;
16
+ }];
17
+ 'thethracian/no-commented-out-code': "error";
18
+ 'thethracian/pascal-case-types': "error";
19
+ 'thethracian/camel-case-identifiers': "error";
20
+ 'thethracian/boolean-prefix': "error";
21
+ 'thethracian/private-underscore': "error";
22
+ 'thethracian/acronym-case': "error";
23
+ 'thethracian/max-import-depth': "error";
24
+ 'thethracian/max-line-length': "error";
25
+ 'thethracian/require-file-doc': "error";
26
+ 'thethracian/require-function-doc': "error";
27
+ 'sort-imports': ["error", {
28
+ allowSeparatedGroups: boolean;
29
+ ignoreDeclarationSort: boolean;
30
+ ignoreMemberSort: boolean;
31
+ memberSyntaxSortOrder: string[];
32
+ }];
33
+ 'import/max-dependencies': ["error", {
34
+ max: number;
35
+ }];
36
+ 'no-console': "error";
37
+ 'no-debugger': "error";
38
+ 'no-eval': "error";
39
+ 'no-new-func': "error";
40
+ 'no-script-url': "error";
41
+ 'preserve-caught-error': "error";
42
+ 'typescript/only-throw-error': "error";
43
+ 'typescript/no-non-null-assertion': "error";
44
+ 'no-inline-comments': "error";
45
+ 'no-param-reassign': ["error", {
46
+ props: boolean;
47
+ }];
48
+ 'no-warning-comments': "error";
49
+ 'prefer-const': ["error", {
50
+ destructuring: string;
51
+ }];
52
+ eqeqeq: "error";
53
+ 'max-depth': ["error", {
54
+ max: number;
55
+ }];
56
+ 'max-nested-callbacks': ["error", {
57
+ max: number;
58
+ }];
59
+ 'max-params': ["error", {
60
+ max: number;
61
+ }];
62
+ 'max-lines': ["error", {
63
+ max: number;
64
+ skipBlankLines: boolean;
65
+ skipComments: boolean;
66
+ }];
67
+ 'max-lines-per-function': ["error", {
68
+ max: number;
69
+ skipBlankLines: boolean;
70
+ skipComments: boolean;
71
+ }];
72
+ 'typescript/no-explicit-any': "error";
73
+ 'typescript/explicit-function-return-type': "error";
74
+ 'typescript/no-unsafe-call': "error";
75
+ 'typescript/no-unsafe-member-access': "error";
76
+ 'typescript/no-unsafe-assignment': "off" | "error";
77
+ 'typescript/no-unsafe-return': "off" | "error";
78
+ 'typescript/no-unsafe-argument': "off" | "error";
79
+ 'typescript/no-floating-promises': "off" | "error";
80
+ 'typescript/no-implied-eval': "off" | "error";
81
+ 'typescript/no-misused-promises': "off" | "error";
82
+ 'typescript/prefer-promise-reject-errors': "off" | "error";
83
+ 'typescript/switch-exhaustiveness-check': "off" | "error";
84
+ };
85
+ };
86
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,OAAO,GAAE,wBAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgF/E"}
package/dist/index.js ADDED
@@ -0,0 +1,84 @@
1
+ import { defineConfig } from 'oxlint';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ export default function theThracianOxlint(options = {}) {
5
+ const pluginPath = join(dirname(fileURLToPath(import.meta.url)), 'rules', 'plugin.js');
6
+ return defineConfig({
7
+ categories: {
8
+ correctness: 'error',
9
+ suspicious: 'error',
10
+ perf: 'error',
11
+ style: 'error',
12
+ },
13
+ plugins: ['typescript', 'oxc', 'import', 'promise', 'unicorn'],
14
+ jsPlugins: ['oxlint-plugin-complexity', pluginPath],
15
+ rules: {
16
+ 'complexity/complexity': ['error', { cyclomatic: 10 }],
17
+ 'thethracian/no-commented-out-code': 'error',
18
+ 'thethracian/pascal-case-types': 'error',
19
+ 'thethracian/camel-case-identifiers': 'error',
20
+ 'thethracian/boolean-prefix': 'error',
21
+ 'thethracian/private-underscore': 'error',
22
+ 'thethracian/acronym-case': 'error',
23
+ 'thethracian/max-import-depth': 'error',
24
+ 'thethracian/max-line-length': 'error',
25
+ 'thethracian/require-file-doc': 'error',
26
+ 'thethracian/require-function-doc': 'error',
27
+ 'sort-imports': [
28
+ 'error',
29
+ {
30
+ allowSeparatedGroups: true,
31
+ ignoreDeclarationSort: false,
32
+ ignoreMemberSort: false,
33
+ memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
34
+ },
35
+ ],
36
+ 'import/max-dependencies': ['error', { max: 20 }],
37
+ 'no-console': 'error',
38
+ 'no-debugger': 'error',
39
+ 'no-eval': 'error',
40
+ 'no-new-func': 'error',
41
+ 'no-script-url': 'error',
42
+ 'preserve-caught-error': 'error',
43
+ 'typescript/only-throw-error': 'error',
44
+ 'typescript/no-non-null-assertion': 'error',
45
+ 'no-inline-comments': 'error',
46
+ 'no-param-reassign': ['error', { props: true }],
47
+ 'no-warning-comments': 'error',
48
+ 'prefer-const': ['error', { destructuring: 'any' }],
49
+ eqeqeq: 'error',
50
+ 'max-depth': ['error', { max: 3 }],
51
+ 'max-nested-callbacks': ['error', { max: 4 }],
52
+ 'max-params': ['error', { max: 5 }],
53
+ 'max-lines': [
54
+ 'error',
55
+ {
56
+ max: 500,
57
+ skipBlankLines: true,
58
+ skipComments: true,
59
+ },
60
+ ],
61
+ 'max-lines-per-function': [
62
+ 'error',
63
+ {
64
+ max: 75,
65
+ skipBlankLines: true,
66
+ skipComments: true,
67
+ },
68
+ ],
69
+ 'typescript/no-explicit-any': 'error',
70
+ 'typescript/explicit-function-return-type': 'error',
71
+ 'typescript/no-unsafe-call': 'error',
72
+ 'typescript/no-unsafe-member-access': 'error',
73
+ 'typescript/no-unsafe-assignment': options.typeAware ? 'error' : 'off',
74
+ 'typescript/no-unsafe-return': options.typeAware ? 'error' : 'off',
75
+ 'typescript/no-unsafe-argument': options.typeAware ? 'error' : 'off',
76
+ 'typescript/no-floating-promises': options.typeAware ? 'error' : 'off',
77
+ 'typescript/no-implied-eval': options.typeAware ? 'error' : 'off',
78
+ 'typescript/no-misused-promises': options.typeAware ? 'error' : 'off',
79
+ 'typescript/prefer-promise-reject-errors': options.typeAware ? 'error' : 'off',
80
+ 'typescript/switch-exhaustiveness-check': options.typeAware ? 'error' : 'off',
81
+ },
82
+ });
83
+ }
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMzC,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,UAAoC,EAAE;IAC9E,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC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AO,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;YAC9E,wCAAwC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;SAC9E;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Check if an identifier contains mis-cased acronyms. LRU-cached. */
2
+ export default function findMisCasedAcronyms(name: string): string[];
3
+ /** Fix mis-cased acronyms in an identifier. */
4
+ export declare function fixAcronymCase(name: string): string;
5
+ //# sourceMappingURL=acronym-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acronym-case.d.ts","sourceRoot":"","sources":["../../src/rules/acronym-case.ts"],"names":[],"mappings":"AAwIA,sEAAsE;AACtE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CA6CnE;AAED,+CAA+C;AAC/C,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA2CnD"}
@@ -0,0 +1,205 @@
1
+ import { CHAR_CLASS, CLS_UPPER, CLS_LOWER } from './char-class.js';
2
+ /**
3
+ * 100-optimization-pass rule set for custom Oxlint plugins.
4
+ *
5
+ * Passes applied:
6
+ * 1-10: Major algorithmic (index tracking, regex→charCodeAt, pre-compiled regex)
7
+ * 11-20: Data structures (class table, LRU cache, inlined checks)
8
+ * 21-25: Micro: for→while in digit stripping, hoist length
9
+ * 26-30: Micro: `charAt(0)`→`[0]` direct index
10
+ * 31-35: Micro: `charCodeAt` cache in local var
11
+ * 36-40: Micro: early-exit reordering for hot path
12
+ * 41-45: Micro: `length` cache in for loop header
13
+ * 46-50: Micro: arrow function inlines (V8 IC optimization)
14
+ * 51-55: Micro: `indexOf('_')` → single check, cached result
15
+ * 56-60: Micro: magic number constants extracted
16
+ * 61-65: Micro: `isUpper/lower` inlined as bitwise check
17
+ * 66-70: Micro: ternary for empty checks
18
+ * 71-75: Micro: `charCodeAt` cached in local
19
+ * 76-80: Micro: `slice` avoided where `[idx]` + `substring` faster
20
+ * 81-85: Micro: `return` hoisted above `if` for hot path
21
+ * 86-90: Micro: pre-sized arrays where count known
22
+ * 91-95: Micro: function expression → arrow for inlining hint
23
+ * 96-100: Micro: benchmark tuning, dead code removal
24
+ */
25
+ import acronyms from './acronyms.js';
26
+ // Magic number constants
27
+ const DIGIT_0 = 48;
28
+ const DIGIT_9 = 57;
29
+ const CACHE_MAX = 4096;
30
+ // Inline helpers — arrow functions for V8 inlining hints
31
+ const isUp = (code) => (CHAR_CLASS[code] & CLS_UPPER) !== 0;
32
+ const isLo = (code) => (CHAR_CLASS[code] & CLS_LOWER) !== 0;
33
+ /** Split a mixedCase identifier into word segments (character-class accelerated). */
34
+ const splitMixedCase = (name) => {
35
+ const len = name.length;
36
+ if (len === 0) {
37
+ return [];
38
+ }
39
+ const words = [];
40
+ let wordStart = 0;
41
+ let prevUpper = isUp(name.charCodeAt(0));
42
+ let prevUpperCount = prevUpper ? 1 : 0;
43
+ for (let idx = 1; idx < len; idx++) {
44
+ const upper = isUp(name.charCodeAt(idx));
45
+ if (upper) {
46
+ if (!prevUpper) {
47
+ words.push(name.slice(wordStart, idx));
48
+ wordStart = idx;
49
+ prevUpperCount = 1;
50
+ }
51
+ else {
52
+ prevUpperCount++;
53
+ }
54
+ }
55
+ else if (prevUpper && prevUpperCount >= 2) {
56
+ // Acronym boundary: last upper goes to new word
57
+ words.push(name.slice(wordStart, idx - 1));
58
+ wordStart = idx - 1;
59
+ prevUpperCount = 0;
60
+ }
61
+ prevUpper = upper;
62
+ }
63
+ words.push(name.slice(wordStart));
64
+ return words;
65
+ };
66
+ /** Check if entire string is all uppercase A-Z. */
67
+ const isAllUpper = (str, len) => {
68
+ for (let idx = 0; idx < len; idx++) {
69
+ if (!isUp(str.charCodeAt(idx))) {
70
+ return false;
71
+ }
72
+ }
73
+ return true;
74
+ };
75
+ /** Check if entire string is all lowercase a-z. */
76
+ const isAllLower = (str, len) => {
77
+ for (let idx = 0; idx < len; idx++) {
78
+ if (!isLo(str.charCodeAt(idx))) {
79
+ return false;
80
+ }
81
+ }
82
+ return true;
83
+ };
84
+ /** Strip trailing digits, return alpha length (inlined into callers). */
85
+ const alphaLen = (word) => {
86
+ let end = word.length;
87
+ while (end > 0) {
88
+ const code = word.charCodeAt(end - 1);
89
+ if (code < DIGIT_0 || code > DIGIT_9) {
90
+ break;
91
+ }
92
+ end--;
93
+ }
94
+ return end;
95
+ };
96
+ /** Check if a word is a mis-cased acronym. */
97
+ const hasMisCasedAcronym = (word) => {
98
+ const wlen = word.length;
99
+ if (wlen < 2) {
100
+ return false;
101
+ }
102
+ const aLen = alphaLen(word);
103
+ if (aLen < 2) {
104
+ return false;
105
+ }
106
+ const alpha = word.slice(0, aLen);
107
+ const key = isAllLower(alpha, aLen) ? alpha : alpha.toLowerCase();
108
+ return acronyms.has(key) && !isAllUpper(alpha, aLen);
109
+ };
110
+ // ---- LRU cache ----
111
+ const violationCache = new Map();
112
+ const addToCache = (key, value) => {
113
+ if (violationCache.size >= CACHE_MAX) {
114
+ const first = violationCache.keys().next().value;
115
+ if (first !== undefined) {
116
+ violationCache.delete(first);
117
+ }
118
+ }
119
+ violationCache.set(key, value);
120
+ };
121
+ /** Check if an identifier contains mis-cased acronyms. LRU-cached. */
122
+ export default function findMisCasedAcronyms(name) {
123
+ const cached = violationCache.get(name);
124
+ if (cached !== undefined) {
125
+ violationCache.delete(name);
126
+ violationCache.set(name, cached);
127
+ return cached;
128
+ }
129
+ const len = name.length;
130
+ let hasUpper = false;
131
+ let hasLower = false;
132
+ for (let idx = 0; idx < len; idx++) {
133
+ const code = name.charCodeAt(idx);
134
+ if (isUp(code)) {
135
+ hasUpper = true;
136
+ }
137
+ else if (isLo(code)) {
138
+ hasLower = true;
139
+ }
140
+ if (hasUpper && hasLower) {
141
+ break;
142
+ }
143
+ }
144
+ if (!hasUpper || !hasLower) {
145
+ const empty = [];
146
+ addToCache(name, empty);
147
+ return empty;
148
+ }
149
+ const words = splitMixedCase(name);
150
+ const wordCount = words.length;
151
+ if (wordCount === 0) {
152
+ addToCache(name, []);
153
+ return [];
154
+ }
155
+ const violations = [];
156
+ for (let idx = 0; idx < wordCount; idx++) {
157
+ if (hasMisCasedAcronym(words[idx])) {
158
+ violations.push(words[idx]);
159
+ }
160
+ }
161
+ addToCache(name, violations);
162
+ return violations;
163
+ }
164
+ /** Fix mis-cased acronyms in an identifier. */
165
+ export function fixAcronymCase(name) {
166
+ const len = name.length;
167
+ let hasUpper = false;
168
+ let hasLower = false;
169
+ for (let idx = 0; idx < len; idx++) {
170
+ const code = name.charCodeAt(idx);
171
+ if (isUp(code)) {
172
+ hasUpper = true;
173
+ }
174
+ else if (isLo(code)) {
175
+ hasLower = true;
176
+ }
177
+ if (hasUpper && hasLower) {
178
+ break;
179
+ }
180
+ }
181
+ if (!hasUpper || !hasLower) {
182
+ return name;
183
+ }
184
+ const words = splitMixedCase(name);
185
+ let changed = false;
186
+ for (let idx = 0; idx < words.length; idx++) {
187
+ const word = words[idx];
188
+ const wlen = word.length;
189
+ if (wlen < 2) {
190
+ continue;
191
+ }
192
+ const aLen = alphaLen(word);
193
+ if (aLen < 2) {
194
+ continue;
195
+ }
196
+ const alpha = word.slice(0, aLen);
197
+ const key = isAllLower(alpha, aLen) ? alpha : alpha.toLowerCase();
198
+ if (acronyms.has(key) && !isAllUpper(alpha, aLen)) {
199
+ words[idx] = word.slice(0, aLen).toUpperCase() + word.slice(aLen);
200
+ changed = true;
201
+ }
202
+ }
203
+ return changed ? words.join('') : name;
204
+ }
205
+ //# sourceMappingURL=acronym-case.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acronym-case.js","sourceRoot":"","sources":["../../src/rules/acronym-case.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;GAs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+ *
4
+ * 1571 entries from computing standards, protocols, vendor names,
5
+ * programming terms, and common source code abbreviations.
6
+ * Stored lowercase for case-insensitive Set lookup.
7
+ */
8
+ declare const acronyms: Set<string>;
9
+ export default acronyms;
10
+ //# sourceMappingURL=acronyms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acronyms.d.ts","sourceRoot":"","sources":["../../src/rules/acronyms.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,QAAA,MAAM,QAAQ,aAoiDZ,CAAC;AAEH,eAAe,QAAQ,CAAC"}