@jameswyse/oxc-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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +213 -0
  3. package/REFERENCE.md +134 -0
  4. package/dist/format.d.ts +5 -0
  5. package/dist/format.js +47 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +97 -0
  8. package/dist/lint.d.ts +33 -0
  9. package/dist/lint.js +493 -0
  10. package/dist/rules/companion-has-owner.d.ts +1 -0
  11. package/dist/rules/companion-has-owner.js +74 -0
  12. package/dist/rules/electron-no-raw-ipc-renderer-exposure.d.ts +1 -0
  13. package/dist/rules/electron-no-raw-ipc-renderer-exposure.js +127 -0
  14. package/dist/rules/electron-no-remote-module.d.ts +1 -0
  15. package/dist/rules/electron-no-remote-module.js +112 -0
  16. package/dist/rules/electron-secure-web-preferences.d.ts +1 -0
  17. package/dist/rules/electron-secure-web-preferences.js +108 -0
  18. package/dist/rules/explicit-api-states.d.ts +1 -0
  19. package/dist/rules/explicit-api-states.js +143 -0
  20. package/dist/rules/import-boundaries.d.ts +1 -0
  21. package/dist/rules/import-boundaries.js +99 -0
  22. package/dist/rules/no-ambient-clock.d.ts +1 -0
  23. package/dist/rules/no-ambient-clock.js +35 -0
  24. package/dist/rules/no-ambient-random.d.ts +1 -0
  25. package/dist/rules/no-ambient-random.js +71 -0
  26. package/dist/rules/no-comments.d.ts +1 -0
  27. package/dist/rules/no-comments.js +64 -0
  28. package/dist/rules/no-deep-ternary.d.ts +1 -0
  29. package/dist/rules/no-deep-ternary.js +32 -0
  30. package/dist/rules/no-edit-proof-assertions.d.ts +1 -0
  31. package/dist/rules/no-edit-proof-assertions.js +120 -0
  32. package/dist/rules/no-env-access.d.ts +1 -0
  33. package/dist/rules/no-env-access.js +35 -0
  34. package/dist/rules/no-fixed-test-delay.d.ts +1 -0
  35. package/dist/rules/no-fixed-test-delay.js +130 -0
  36. package/dist/rules/no-forwarding-module.d.ts +1 -0
  37. package/dist/rules/no-forwarding-module.js +158 -0
  38. package/dist/rules/no-generic-file-suffix.d.ts +1 -0
  39. package/dist/rules/no-generic-file-suffix.js +74 -0
  40. package/dist/rules/no-pass-through-function.d.ts +1 -0
  41. package/dist/rules/no-pass-through-function.js +106 -0
  42. package/dist/rules/no-swallowed-errors.d.ts +1 -0
  43. package/dist/rules/no-swallowed-errors.js +168 -0
  44. package/dist/rules/no-test-timeout-overrides.d.ts +1 -0
  45. package/dist/rules/no-test-timeout-overrides.js +105 -0
  46. package/dist/rules/no-vacuous-test-assertions.d.ts +1 -0
  47. package/dist/rules/no-vacuous-test-assertions.js +71 -0
  48. package/dist/rules/server-action-guard.d.ts +1 -0
  49. package/dist/rules/server-action-guard.js +109 -0
  50. package/dist/rules/statement-spacing.d.ts +1 -0
  51. package/dist/rules/statement-spacing.js +29 -0
  52. package/dist/rules/type-guard-name.d.ts +1 -0
  53. package/dist/rules/type-guard-name.js +59 -0
  54. package/dist/shared/index.d.ts +26 -0
  55. package/dist/shared/index.js +260 -0
  56. package/dist/shared/rule-options.d.ts +2 -0
  57. package/dist/shared/rule-options.js +8 -0
  58. package/dist/vendor/anti-slop/effect/rules/no-manual-effect-error-tag.d.ts +1 -0
  59. package/dist/vendor/anti-slop/effect/rules/no-manual-effect-error-tag.js +35 -0
  60. package/dist/vendor/anti-slop/effect/rules/no-service-constructor-imports.d.ts +1 -0
  61. package/dist/vendor/anti-slop/effect/rules/no-service-constructor-imports.js +48 -0
  62. package/dist/vendor/anti-slop/effect/shared/tagged-values.d.ts +9 -0
  63. package/dist/vendor/anti-slop/effect/shared/tagged-values.js +65 -0
  64. package/dist/vendor/anti-slop/rules/no-array-filter-map.d.ts +1 -0
  65. package/dist/vendor/anti-slop/rules/no-array-filter-map.js +40 -0
  66. package/dist/vendor/anti-slop/rules/no-chained-type-assertions.d.ts +1 -0
  67. package/dist/vendor/anti-slop/rules/no-chained-type-assertions.js +58 -0
  68. package/dist/vendor/anti-slop/rules/no-conditional-empty-object-spread.d.ts +1 -0
  69. package/dist/vendor/anti-slop/rules/no-conditional-empty-object-spread.js +41 -0
  70. package/dist/vendor/anti-slop/rules/no-known-value-widening.d.ts +1 -0
  71. package/dist/vendor/anti-slop/rules/no-known-value-widening.js +333 -0
  72. package/dist/vendor/anti-slop/rules/no-module-mocking.d.ts +1 -0
  73. package/dist/vendor/anti-slop/rules/no-module-mocking.js +74 -0
  74. package/dist/vendor/anti-slop/rules/no-object-parameters.d.ts +1 -0
  75. package/dist/vendor/anti-slop/rules/no-object-parameters.js +59 -0
  76. package/dist/vendor/anti-slop/rules/no-reduce-accumulator-copy.d.ts +1 -0
  77. package/dist/vendor/anti-slop/rules/no-reduce-accumulator-copy.js +124 -0
  78. package/dist/vendor/anti-slop/rules/no-reflect-apply.d.ts +1 -0
  79. package/dist/vendor/anti-slop/rules/no-reflect-apply.js +26 -0
  80. package/dist/vendor/anti-slop/rules/no-reflect-get.d.ts +1 -0
  81. package/dist/vendor/anti-slop/rules/no-reflect-get.js +26 -0
  82. package/dist/vendor/anti-slop/rules/no-runtime-typeof.d.ts +1 -0
  83. package/dist/vendor/anti-slop/rules/no-runtime-typeof.js +63 -0
  84. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.d.ts +1 -0
  85. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js +37 -0
  86. package/dist/vendor/anti-slop/rules/no-unknown-returns.d.ts +1 -0
  87. package/dist/vendor/anti-slop/rules/no-unknown-returns.js +61 -0
  88. package/dist/vendor/anti-slop/rules/no-unknown-type-aliases.d.ts +1 -0
  89. package/dist/vendor/anti-slop/rules/no-unknown-type-aliases.js +38 -0
  90. package/dist/vendor/anti-slop/rules/no-unsafe-dictionary-type.d.ts +1 -0
  91. package/dist/vendor/anti-slop/rules/no-unsafe-dictionary-type.js +143 -0
  92. package/dist/vendor/anti-slop/rules/no-widen-then-assert.d.ts +1 -0
  93. package/dist/vendor/anti-slop/rules/no-widen-then-assert.js +288 -0
  94. package/dist/vendor/anti-slop/shared/array-method.d.ts +10 -0
  95. package/dist/vendor/anti-slop/shared/array-method.js +95 -0
  96. package/dist/vendor/anti-slop/shared/dictionary-types.d.ts +23 -0
  97. package/dist/vendor/anti-slop/shared/dictionary-types.js +408 -0
  98. package/dist/vendor/anti-slop/shared/function-parameters.d.ts +6 -0
  99. package/dist/vendor/anti-slop/shared/function-parameters.js +41 -0
  100. package/dist/vendor/anti-slop/shared/lexical-type-parameters.d.ts +4 -0
  101. package/dist/vendor/anti-slop/shared/lexical-type-parameters.js +32 -0
  102. package/dist/vendor/anti-slop/shared/reflect-method.d.ts +3 -0
  103. package/dist/vendor/anti-slop/shared/reflect-method.js +24 -0
  104. package/dist/vendor/anti-slop/shared/scope.d.ts +3 -0
  105. package/dist/vendor/anti-slop/shared/scope.js +12 -0
  106. package/dist/vendor/anti-slop/shared/type-alias-resolution.d.ts +21 -0
  107. package/dist/vendor/anti-slop/shared/type-alias-resolution.js +147 -0
  108. package/dist/vendor/eslint-stylistic/padding-line-ast.d.ts +14 -0
  109. package/dist/vendor/eslint-stylistic/padding-line-ast.js +19 -0
  110. package/dist/vendor/eslint-stylistic/padding-line-between-statements.d.ts +91 -0
  111. package/dist/vendor/eslint-stylistic/padding-line-between-statements.js +493 -0
  112. package/package.json +89 -0
  113. package/src/vendor/anti-slop/LICENSE +21 -0
  114. package/src/vendor/eslint-stylistic/LICENSE +22 -0
  115. package/tsconfig.base.json +10 -0
@@ -0,0 +1,493 @@
1
+ import { isClosingBraceToken, isFunction, isNotSemicolonToken, isParenthesized, isSemicolonToken, isSingleLine, isTokenOnSameLine, isTopLevelExpressionStatement, LINEBREAKS, skipChainExpression, } from "./padding-line-ast.js";
2
+ const CJS_EXPORT = /^(?:module\s*\.\s*)?exports(?:\s*\.|\s*\[|$)/u;
3
+ const CJS_IMPORT = /^require\(/u;
4
+ const LT = `[${Array.from(LINEBREAKS).join("")}]`;
5
+ const PADDING_LINE_SEQUENCE = new RegExp(String.raw `^(\s*?${LT})\s*${LT}(\s*;?)$`, "u");
6
+ function isStatementMatcherList(option) {
7
+ return Array.isArray(option);
8
+ }
9
+ function isSelectorOption(option) {
10
+ return typeof option === "object" && !isStatementMatcherList(option);
11
+ }
12
+ function newKeywordTester(type, keyword) {
13
+ return {
14
+ test(node, sourceCode) {
15
+ const isSameKeyword = sourceCode.getFirstToken(node)?.value === keyword;
16
+ const isSameType = Array.isArray(type) ? type.includes(node.type) : type === node.type;
17
+ return isSameKeyword && isSameType;
18
+ },
19
+ };
20
+ }
21
+ function newNodeTypeTester(type) {
22
+ return { test: (node) => node.type === type };
23
+ }
24
+ function isIIFEStatement(node) {
25
+ if (node.type === "ExpressionStatement") {
26
+ let expression = skipChainExpression(node.expression);
27
+ if (expression.type === "UnaryExpression") {
28
+ expression = skipChainExpression(expression.argument);
29
+ }
30
+ if (expression.type === "CallExpression") {
31
+ let node2 = expression.callee;
32
+ while (node2.type === "SequenceExpression") {
33
+ const lastExpression = node2.expressions.at(-1);
34
+ if (lastExpression === void 0) {
35
+ throw new Error("Padding rule invariant: sequence expression is empty");
36
+ }
37
+ node2 = lastExpression;
38
+ }
39
+ return isFunction(node2);
40
+ }
41
+ }
42
+ return false;
43
+ }
44
+ function isCJSRequire(node) {
45
+ if (node.type === "VariableDeclaration") {
46
+ const declaration = node.declarations[0];
47
+ if (declaration?.init) {
48
+ let call = declaration.init;
49
+ while (call.type === "MemberExpression") {
50
+ call = call.object;
51
+ }
52
+ if (call.type === "CallExpression" && call.callee.type === "Identifier") {
53
+ return call.callee.name === "require";
54
+ }
55
+ }
56
+ }
57
+ return false;
58
+ }
59
+ function isBlockLikeStatement(node, sourceCode) {
60
+ if (node.type === "DoWhileStatement" && node.body.type === "BlockStatement") {
61
+ return true;
62
+ }
63
+ if (isIIFEStatement(node)) {
64
+ return true;
65
+ }
66
+ const lastToken = sourceCode.getLastToken(node, isNotSemicolonToken);
67
+ const belongingNode = lastToken && isClosingBraceToken(lastToken)
68
+ ? sourceCode.getNodeByRangeIndex(lastToken.range[0])
69
+ : null;
70
+ return (belongingNode !== null &&
71
+ (belongingNode.type === "BlockStatement" || belongingNode.type === "SwitchStatement"));
72
+ }
73
+ function isDirective(node, sourceCode) {
74
+ return (isTopLevelExpressionStatement(node) &&
75
+ node.expression.type === "Literal" &&
76
+ typeof node.expression.value === "string" &&
77
+ !isParenthesized(node.expression, sourceCode));
78
+ }
79
+ function isDirectivePrologue(node, sourceCode) {
80
+ if (isDirective(node, sourceCode) &&
81
+ node.parent &&
82
+ "body" in node.parent &&
83
+ Array.isArray(node.parent.body)) {
84
+ for (const sibling of node.parent.body) {
85
+ if (sibling === node) {
86
+ break;
87
+ }
88
+ if (!isDirective(sibling, sourceCode)) {
89
+ return false;
90
+ }
91
+ }
92
+ return true;
93
+ }
94
+ return false;
95
+ }
96
+ function isCJSExport(node) {
97
+ if (node.type === "ExpressionStatement") {
98
+ const expression = node.expression;
99
+ if (expression.type === "AssignmentExpression") {
100
+ let left = expression.left;
101
+ if (left.type === "MemberExpression") {
102
+ while (left.object.type === "MemberExpression") {
103
+ left = left.object;
104
+ }
105
+ return (left.object.type === "Identifier" &&
106
+ (left.object.name === "exports" ||
107
+ (left.object.name === "module" &&
108
+ left.property.type === "Identifier" &&
109
+ left.property.name === "exports")));
110
+ }
111
+ }
112
+ }
113
+ return false;
114
+ }
115
+ function isExpression(node, sourceCode) {
116
+ return node.type === "ExpressionStatement" && !isDirectivePrologue(node, sourceCode);
117
+ }
118
+ function getActualLastToken(node, sourceCode) {
119
+ const semiToken = sourceCode.getLastToken(node);
120
+ if (semiToken === null) {
121
+ throw new Error("Padding rule invariant: statement has no last token");
122
+ }
123
+ const prevToken = sourceCode.getTokenBefore(semiToken);
124
+ const nextToken = sourceCode.getTokenAfter(semiToken);
125
+ const isSemicolonLessStyle = prevToken !== null &&
126
+ nextToken !== null &&
127
+ prevToken.range[0] >= node.range[0] &&
128
+ isSemicolonToken(semiToken) &&
129
+ !isTokenOnSameLine(prevToken, semiToken) &&
130
+ isTokenOnSameLine(semiToken, nextToken);
131
+ return isSemicolonLessStyle ? prevToken : semiToken;
132
+ }
133
+ function replacerToRemovePaddingLines(_, trailingSpaces, indentSpaces) {
134
+ return trailingSpaces + indentSpaces;
135
+ }
136
+ function getReportLoc(node, sourceCode) {
137
+ if (isSingleLine(node)) {
138
+ return node.loc;
139
+ }
140
+ const line = node.loc.start.line;
141
+ const sourceLine = sourceCode.lines[line - 1];
142
+ if (sourceLine === void 0) {
143
+ throw new Error("Padding rule invariant: statement source line is missing");
144
+ }
145
+ return { start: node.loc.start, end: { line, column: sourceLine.length } };
146
+ }
147
+ function verifyForAny() { }
148
+ function verifyForNever(context, _, nextNode, paddingLines) {
149
+ if (paddingLines.length === 0) {
150
+ return;
151
+ }
152
+ context.report({
153
+ node: nextNode,
154
+ messageId: "unexpectedBlankLine",
155
+ loc: getReportLoc(nextNode, context.sourceCode),
156
+ fix(fixer) {
157
+ if (paddingLines.length >= 2) {
158
+ return null;
159
+ }
160
+ const paddingPair = paddingLines[0];
161
+ if (paddingPair === void 0) {
162
+ throw new Error("Padding rule invariant: reported padding pair is missing");
163
+ }
164
+ const [prevToken, nextToken] = paddingPair;
165
+ const start = prevToken.range[1];
166
+ const end = nextToken.range[0];
167
+ const text = context.sourceCode.text
168
+ .slice(start, end)
169
+ .replace(PADDING_LINE_SEQUENCE, replacerToRemovePaddingLines);
170
+ return fixer.replaceTextRange([start, end], text);
171
+ },
172
+ });
173
+ }
174
+ function verifyForAlways(context, prevNode, nextNode, paddingLines) {
175
+ if (paddingLines.length > 0) {
176
+ return;
177
+ }
178
+ context.report({
179
+ node: nextNode,
180
+ messageId: "expectedBlankLine",
181
+ loc: getReportLoc(nextNode, context.sourceCode),
182
+ fix(fixer) {
183
+ const sourceCode = context.sourceCode;
184
+ let prevToken = getActualLastToken(prevNode, sourceCode);
185
+ const nextToken = sourceCode.getFirstTokenBetween(prevToken, nextNode, {
186
+ includeComments: true,
187
+ filter(token) {
188
+ if (isTokenOnSameLine(prevToken, token)) {
189
+ prevToken = token;
190
+ return false;
191
+ }
192
+ return true;
193
+ },
194
+ }) ?? nextNode;
195
+ const insertText = isTokenOnSameLine(prevToken, nextToken) ? "\n\n" : "\n";
196
+ return fixer.insertTextAfter(prevToken, insertText);
197
+ },
198
+ });
199
+ }
200
+ const PaddingTypes = {
201
+ any: { verify: verifyForAny },
202
+ never: { verify: verifyForNever },
203
+ always: { verify: verifyForAlways },
204
+ };
205
+ function hasCJSExportText(node, sourceCode) {
206
+ return (node.type === "ExpressionStatement" &&
207
+ node.expression.type === "AssignmentExpression" &&
208
+ CJS_EXPORT.test(sourceCode.getText(node.expression.left)));
209
+ }
210
+ function hasCJSImportText(node, sourceCode) {
211
+ if (node.type !== "VariableDeclaration") {
212
+ return false;
213
+ }
214
+ const init = node.declarations[0]?.init ?? null;
215
+ return init !== null && CJS_IMPORT.test(sourceCode.getText(init));
216
+ }
217
+ const MaybeMultilineStatementType = {
218
+ "block-like": { test: isBlockLikeStatement },
219
+ expression: { test: isExpression },
220
+ return: newKeywordTester("ReturnStatement", "return"),
221
+ export: newKeywordTester(["ExportAllDeclaration", "ExportDefaultDeclaration", "ExportNamedDeclaration"], "export"),
222
+ var: newKeywordTester("VariableDeclaration", "var"),
223
+ let: newKeywordTester("VariableDeclaration", "let"),
224
+ const: newKeywordTester("VariableDeclaration", "const"),
225
+ using: {
226
+ test: (node) => node.type === "VariableDeclaration" && (node.kind === "using" || node.kind === "await using"),
227
+ },
228
+ type: newKeywordTester("TSTypeAliasDeclaration", "type"),
229
+ };
230
+ const BaseStatementTypes = {
231
+ "*": { test: () => true },
232
+ exports: { test: isCJSExport },
233
+ require: { test: isCJSRequire },
234
+ directive: { test: isDirectivePrologue },
235
+ iife: { test: isIIFEStatement },
236
+ block: newNodeTypeTester("BlockStatement"),
237
+ empty: newNodeTypeTester("EmptyStatement"),
238
+ function: newNodeTypeTester("FunctionDeclaration"),
239
+ "ts-method": newNodeTypeTester("TSMethodSignature"),
240
+ break: newKeywordTester("BreakStatement", "break"),
241
+ case: newKeywordTester("SwitchCase", "case"),
242
+ class: newKeywordTester("ClassDeclaration", "class"),
243
+ continue: newKeywordTester("ContinueStatement", "continue"),
244
+ debugger: newKeywordTester("DebuggerStatement", "debugger"),
245
+ default: newKeywordTester(["SwitchCase", "ExportDefaultDeclaration"], "default"),
246
+ do: newKeywordTester("DoWhileStatement", "do"),
247
+ for: newKeywordTester(["ForStatement", "ForInStatement", "ForOfStatement"], "for"),
248
+ if: newKeywordTester("IfStatement", "if"),
249
+ import: newKeywordTester("ImportDeclaration", "import"),
250
+ switch: newKeywordTester("SwitchStatement", "switch"),
251
+ throw: newKeywordTester("ThrowStatement", "throw"),
252
+ try: newKeywordTester("TryStatement", "try"),
253
+ while: newKeywordTester(["WhileStatement", "DoWhileStatement"], "while"),
254
+ with: newKeywordTester("WithStatement", "with"),
255
+ "cjs-export": { test: hasCJSExportText },
256
+ "cjs-import": { test: hasCJSImportText },
257
+ enum: newKeywordTester("TSEnumDeclaration", "enum"),
258
+ interface: newKeywordTester("TSInterfaceDeclaration", "interface"),
259
+ "function-overload": newNodeTypeTester("TSDeclareFunction"),
260
+ };
261
+ const StatementTypes = new Map([
262
+ ...Object.entries(BaseStatementTypes),
263
+ ...Object.entries(MaybeMultilineStatementType).flatMap(([key, value]) => [
264
+ [key, value],
265
+ [
266
+ `singleline-${key}`,
267
+ {
268
+ ...value,
269
+ test: (node, sourceCode) => value.test(node, sourceCode) && isSingleLine(node),
270
+ },
271
+ ],
272
+ [
273
+ `multiline-${key}`,
274
+ {
275
+ ...value,
276
+ test: (node, sourceCode) => value.test(node, sourceCode) && !isSingleLine(node),
277
+ },
278
+ ],
279
+ ]),
280
+ ]);
281
+ function createPaddingLineRule(options) {
282
+ return {
283
+ meta: {
284
+ type: "layout",
285
+ docs: { description: "Require or disallow padding lines between statements" },
286
+ fixable: "whitespace",
287
+ hasSuggestions: false,
288
+ schema: {
289
+ $defs: {
290
+ paddingType: { type: "string", enum: Object.keys(PaddingTypes) },
291
+ statementType: { type: "string", enum: Array.from(StatementTypes.keys()) },
292
+ selectorOption: {
293
+ type: "object",
294
+ properties: {
295
+ selector: { type: "string" },
296
+ lineMode: { type: "string", enum: ["any", "singleline", "multiline"] },
297
+ },
298
+ required: ["selector"],
299
+ additionalProperties: false,
300
+ },
301
+ statementMatcher: {
302
+ anyOf: [{ $ref: "#/$defs/statementType" }, { $ref: "#/$defs/selectorOption" }],
303
+ },
304
+ statementOption: {
305
+ anyOf: [
306
+ { $ref: "#/$defs/statementMatcher" },
307
+ {
308
+ type: "array",
309
+ items: { $ref: "#/$defs/statementMatcher" },
310
+ minItems: 1,
311
+ uniqueItems: true,
312
+ additionalItems: false,
313
+ },
314
+ ],
315
+ },
316
+ },
317
+ type: "array",
318
+ additionalItems: false,
319
+ items: {
320
+ type: "object",
321
+ properties: {
322
+ blankLine: { $ref: "#/$defs/paddingType" },
323
+ prev: { $ref: "#/$defs/statementOption" },
324
+ next: { $ref: "#/$defs/statementOption" },
325
+ },
326
+ additionalProperties: false,
327
+ required: ["blankLine", "prev", "next"],
328
+ },
329
+ },
330
+ messages: {
331
+ unexpectedBlankLine: "Unexpected blank line before this statement.",
332
+ expectedBlankLine: "Expected blank line before this statement.",
333
+ },
334
+ },
335
+ create(context) {
336
+ const sourceCode = context.sourceCode;
337
+ const selectorMatchedNodes = new Map();
338
+ const pendingPairs = [];
339
+ function collectSelectorOption(option) {
340
+ if (isStatementMatcherList(option)) {
341
+ for (const item of option) {
342
+ collectSelectorOption(item);
343
+ }
344
+ return;
345
+ }
346
+ if (!isSelectorOption(option)) {
347
+ return;
348
+ }
349
+ selectorMatchedNodes.set(option.selector, new Set());
350
+ }
351
+ for (const configure of options) {
352
+ collectSelectorOption(configure.prev);
353
+ collectSelectorOption(configure.next);
354
+ }
355
+ let scopeInfo = null;
356
+ function enterScope() {
357
+ scopeInfo = { upper: scopeInfo, prevNode: null };
358
+ }
359
+ function exitScope() {
360
+ if (scopeInfo) {
361
+ scopeInfo = scopeInfo.upper;
362
+ }
363
+ }
364
+ function match(node, type) {
365
+ let innerStatementNode = node;
366
+ while (innerStatementNode.type === "LabeledStatement") {
367
+ innerStatementNode = innerStatementNode.body;
368
+ }
369
+ if (isStatementMatcherList(type)) {
370
+ return type.some((item) => match(innerStatementNode, item));
371
+ }
372
+ if (isSelectorOption(type)) {
373
+ const matchedNodes = selectorMatchedNodes.get(type.selector);
374
+ if (!matchedNodes?.has(innerStatementNode)) {
375
+ return false;
376
+ }
377
+ const lineMode = type.lineMode;
378
+ if (lineMode === "singleline") {
379
+ return isSingleLine(innerStatementNode);
380
+ }
381
+ else if (lineMode === "multiline") {
382
+ return !isSingleLine(innerStatementNode);
383
+ }
384
+ return true;
385
+ }
386
+ else {
387
+ const statementType = StatementTypes.get(type);
388
+ if (statementType === void 0) {
389
+ throw new Error(`Padding rule invariant: unsupported statement type ${type}`);
390
+ }
391
+ return statementType.test(innerStatementNode, sourceCode);
392
+ }
393
+ }
394
+ function getPaddingType(prevNode, nextNode) {
395
+ for (let i = options.length - 1; i >= 0; --i) {
396
+ const configure = options[i];
397
+ if (configure === void 0) {
398
+ throw new Error("Padding rule invariant: configuration entry is missing");
399
+ }
400
+ if (match(prevNode, configure.prev) && match(nextNode, configure.next)) {
401
+ return PaddingTypes[configure.blankLine];
402
+ }
403
+ }
404
+ return PaddingTypes.any;
405
+ }
406
+ function getPaddingLineSequences(prevNode, nextNode) {
407
+ const pairs = [];
408
+ let prevToken = getActualLastToken(prevNode, sourceCode);
409
+ if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
410
+ do {
411
+ const token = sourceCode.getTokenAfter(prevToken, { includeComments: true });
412
+ if (token === null) {
413
+ throw new Error("Padding rule invariant: token after padding is missing");
414
+ }
415
+ if (token.loc.start.line - prevToken.loc.end.line >= 2) {
416
+ pairs.push([prevToken, token]);
417
+ }
418
+ prevToken = token;
419
+ } while (prevToken.range[0] < nextNode.range[0]);
420
+ }
421
+ return pairs;
422
+ }
423
+ function verify(node) {
424
+ if (!node.parent ||
425
+ ![
426
+ "BlockStatement",
427
+ "Program",
428
+ "StaticBlock",
429
+ "SwitchCase",
430
+ "SwitchStatement",
431
+ "TSInterfaceBody",
432
+ "TSModuleBlock",
433
+ "TSTypeLiteral",
434
+ ].includes(node.parent.type)) {
435
+ return;
436
+ }
437
+ if (scopeInfo === null) {
438
+ throw new Error("Padding rule invariant: statement is outside a scope");
439
+ }
440
+ const prevNode = scopeInfo.prevNode;
441
+ if (prevNode) {
442
+ pendingPairs.push({ prevNode, nextNode: node });
443
+ }
444
+ scopeInfo.prevNode = node;
445
+ }
446
+ function verifyPendingPairs() {
447
+ for (const { prevNode, nextNode } of pendingPairs) {
448
+ const type = getPaddingType(prevNode, nextNode);
449
+ const paddingLines = getPaddingLineSequences(prevNode, nextNode);
450
+ type.verify(context, prevNode, nextNode, paddingLines);
451
+ }
452
+ }
453
+ function verifyThenEnterScope(node) {
454
+ verify(node);
455
+ enterScope();
456
+ }
457
+ const selectorMatchListeners = Object.fromEntries(Array.from(selectorMatchedNodes.keys(), (selector) => [
458
+ selector,
459
+ (node) => {
460
+ selectorMatchedNodes.get(selector)?.add(node);
461
+ },
462
+ ]));
463
+ return {
464
+ Program: enterScope,
465
+ "Program:exit": () => {
466
+ verifyPendingPairs();
467
+ exitScope();
468
+ },
469
+ BlockStatement: enterScope,
470
+ "BlockStatement:exit": exitScope,
471
+ SwitchStatement: enterScope,
472
+ "SwitchStatement:exit": exitScope,
473
+ SwitchCase: verifyThenEnterScope,
474
+ "SwitchCase:exit": exitScope,
475
+ StaticBlock: enterScope,
476
+ "StaticBlock:exit": exitScope,
477
+ TSInterfaceBody: enterScope,
478
+ "TSInterfaceBody:exit": exitScope,
479
+ TSModuleBlock: enterScope,
480
+ "TSModuleBlock:exit": exitScope,
481
+ TSTypeLiteral: enterScope,
482
+ "TSTypeLiteral:exit": exitScope,
483
+ TSDeclareFunction: verifyThenEnterScope,
484
+ "TSDeclareFunction:exit": exitScope,
485
+ TSMethodSignature: verifyThenEnterScope,
486
+ "TSMethodSignature:exit": exitScope,
487
+ ":statement": verify,
488
+ ...selectorMatchListeners,
489
+ };
490
+ },
491
+ };
492
+ }
493
+ export { createPaddingLineRule as default };
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@jameswyse/oxc-config",
3
+ "version": "0.1.0",
4
+ "description": "Opinionated Oxlint and Oxfmt configs with custom rules for TypeScript and JavaScript projects",
5
+ "keywords": [
6
+ "config",
7
+ "format",
8
+ "lint",
9
+ "nextjs",
10
+ "oxc",
11
+ "oxfmt",
12
+ "oxlint",
13
+ "react",
14
+ "typescript"
15
+ ],
16
+ "homepage": "https://github.com/jameswyse/oxc-config#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/jameswyse/oxc-config/issues"
19
+ },
20
+ "license": "MIT",
21
+ "author": "James Wyse",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/jameswyse/oxc-config.git"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src/vendor/anti-slop/LICENSE",
29
+ "src/vendor/eslint-stylistic/LICENSE",
30
+ "tsconfig.base.json",
31
+ "REFERENCE.md"
32
+ ],
33
+ "type": "module",
34
+ "exports": {
35
+ "./oxlint": "./dist/lint.js",
36
+ "./oxfmt": "./dist/format.js",
37
+ "./wyse": "./dist/index.js",
38
+ "./tsconfig": "./tsconfig.base.json"
39
+ },
40
+ "dependencies": {
41
+ "@e18e/eslint-plugin": "0.8.1",
42
+ "@oxlint/plugins": "1.86.0",
43
+ "eslint-plugin-react-you-might-not-need-an-effect": "1.0.2"
44
+ },
45
+ "devDependencies": {
46
+ "@changesets/cli": "3.0.3",
47
+ "@types/node": "^22.20.5",
48
+ "oxfmt": "0.71.0",
49
+ "oxlint": "1.86.0",
50
+ "oxlint-tsgolint": "7.0.2003",
51
+ "typescript": "7.0.2"
52
+ },
53
+ "peerDependencies": {
54
+ "oxfmt": ">=0.71.0 <1",
55
+ "oxlint": ">=1.86.0 <2",
56
+ "oxlint-tsgolint": ">=7.0.2003 <8"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "oxfmt": {
60
+ "optional": true
61
+ },
62
+ "oxlint-tsgolint": {
63
+ "optional": true
64
+ }
65
+ },
66
+ "devEngines": {
67
+ "packageManager": {
68
+ "name": "pnpm",
69
+ "version": "12.6.0"
70
+ },
71
+ "runtime": {
72
+ "name": "node",
73
+ "version": "24.18.0",
74
+ "onFail": "download"
75
+ }
76
+ },
77
+ "engines": {
78
+ "node": ">=22.23.0"
79
+ },
80
+ "scripts": {
81
+ "build": "tsc -p tsconfig.build.json",
82
+ "check": "pnpm test && pnpm lint && pnpm typecheck && pnpm format:check && pnpm build",
83
+ "format": "oxfmt .",
84
+ "format:check": "oxfmt --check .",
85
+ "lint": "oxlint .",
86
+ "test": "node --test \"src/**/*.test.ts\"",
87
+ "typecheck": "tsc"
88
+ }
89
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dillon Mulroy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
4
+ Copyright (c) 2023-PRESENT ESLint Stylistic contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "strict": true,
5
+ "noUncheckedIndexedAccess": true,
6
+ "exactOptionalPropertyTypes": true,
7
+ "noImplicitOverride": true,
8
+ "noFallthroughCasesInSwitch": true
9
+ }
10
+ }