@kamaal111/kamaal-quality-config 0.1.0 → 0.2.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/README.md +9 -1
- package/dist/oxlint.d.ts.map +1 -1
- package/dist/oxlint.js +18 -1
- package/dist/oxlint.js.map +1 -1
- package/dist/oxlintrc.json +10 -0
- package/dist/plugins/consistent-inline-type-imports.d.ts +36 -0
- package/dist/plugins/consistent-inline-type-imports.d.ts.map +1 -0
- package/dist/plugins/consistent-inline-type-imports.js +47 -0
- package/dist/plugins/consistent-inline-type-imports.js.map +1 -0
- package/dist/plugins/no-nullish-check-first-ternary.d.ts +45 -0
- package/dist/plugins/no-nullish-check-first-ternary.d.ts.map +1 -0
- package/dist/plugins/no-nullish-check-first-ternary.js +52 -0
- package/dist/plugins/no-nullish-check-first-ternary.js.map +1 -0
- package/dist/plugins/rule-context.d.ts +19 -0
- package/dist/plugins/rule-context.d.ts.map +1 -0
- package/dist/plugins/rule-context.js +2 -0
- package/dist/plugins/rule-context.js.map +1 -0
- package/package.json +7 -3
- package/src/plugins/consistent-inline-type-imports.ts +76 -0
- package/src/plugins/no-nullish-check-first-ternary.ts +102 -0
package/README.md
CHANGED
|
@@ -5,7 +5,15 @@ Kamaal Farah's shared [oxlint](https://oxc.rs) quality configs.
|
|
|
5
5
|
Currently enables every rule from [`@kamaal111/oxlint-plugin-anti-slop`](https://github.com/kamaal111/anti-slop),
|
|
6
6
|
Kamaal's fork of [`dmmulroy/anti-slop`](https://github.com/dmmulroy/anti-slop), plus a curated set of
|
|
7
7
|
rules from oxlint's built-in `typescript`, `unicorn`, `oxc`, and `vitest` plugins and from
|
|
8
|
-
`eslint-plugin-import` (via oxlint's `jsPlugins`)
|
|
8
|
+
`eslint-plugin-import` (via oxlint's `jsPlugins`), plus two hand-written local rules:
|
|
9
|
+
|
|
10
|
+
- `kamaal-imports/no-all-inline-type-imports` — forbids `import { type A, type B } from 'x'` in favor
|
|
11
|
+
of a top-level `import type { A, B } from 'x'`.
|
|
12
|
+
- `kamaal-ternary/no-nullish-check-first-ternary` — forbids ternaries that check for a nullish value
|
|
13
|
+
first (e.g. `x == null ? undefined : x.trim()`), requiring the value-producing branch first instead
|
|
14
|
+
(`x != null ? x.trim() : undefined`).
|
|
15
|
+
|
|
16
|
+
More rule sources will be folded in over time.
|
|
9
17
|
|
|
10
18
|
## Table of contents
|
|
11
19
|
|
package/dist/oxlint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2FuB,KAAK;gBAAS,eAAe"}
|
package/dist/oxlint.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
import antiSlopPlugin from '@kamaal111/oxlint-plugin-anti-slop';
|
|
2
2
|
import { defineConfig } from 'oxlint';
|
|
3
|
-
|
|
3
|
+
import consistentInlineTypeImportsPlugin from './plugins/consistent-inline-type-imports.js';
|
|
4
|
+
import noNullishCheckFirstTernaryPlugin from './plugins/no-nullish-check-first-ternary.js';
|
|
5
|
+
function pluginRules(namespace, ruleNames) {
|
|
6
|
+
return Object.fromEntries(ruleNames.map(ruleName => [`${namespace}/${ruleName}`, 'error']));
|
|
7
|
+
}
|
|
8
|
+
const antiSlopRules = pluginRules('anti-slop', Object.keys(antiSlopPlugin.rules));
|
|
9
|
+
const consistentInlineTypeImportsRules = pluginRules(consistentInlineTypeImportsPlugin.meta.name, Object.keys(consistentInlineTypeImportsPlugin.rules));
|
|
10
|
+
const noNullishCheckFirstTernaryRules = pluginRules(noNullishCheckFirstTernaryPlugin.meta.name, Object.keys(noNullishCheckFirstTernaryPlugin.rules));
|
|
4
11
|
export default defineConfig({
|
|
5
12
|
plugins: ['typescript', 'unicorn', 'oxc', 'vitest'],
|
|
6
13
|
jsPlugins: [
|
|
7
14
|
{ name: 'anti-slop', specifier: '@kamaal111/oxlint-plugin-anti-slop' },
|
|
8
15
|
{ name: 'import-js', specifier: 'eslint-plugin-import' },
|
|
16
|
+
{
|
|
17
|
+
name: consistentInlineTypeImportsPlugin.meta.name,
|
|
18
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/consistent-inline-type-imports',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: noNullishCheckFirstTernaryPlugin.meta.name,
|
|
22
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/no-nullish-check-first-ternary',
|
|
23
|
+
},
|
|
9
24
|
],
|
|
10
25
|
options: { typeAware: true },
|
|
11
26
|
categories: { correctness: 'error' },
|
|
12
27
|
rules: {
|
|
13
28
|
...antiSlopRules,
|
|
29
|
+
...consistentInlineTypeImportsRules,
|
|
30
|
+
...noNullishCheckFirstTernaryRules,
|
|
14
31
|
curly: 'error',
|
|
15
32
|
'typescript/no-deprecated': 'error',
|
|
16
33
|
'typescript/consistent-type-imports': 'error',
|
package/dist/oxlint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.js","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,
|
|
1
|
+
{"version":3,"file":"oxlint.js","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,iCAAiC,MAAM,6CAA6C,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O;QAC/B,6BAA6B,EAAE,CAAC,OAAO,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;QACrE,mCAAmC,EAAE,OAAO;QAC5C,iBAAiB,EAAE;YACjB,OAAO;YACP;gBACE,MAAM,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;gBAC3E,kBAAkB,EAAE,QAAQ;gBAC5B,WAAW,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE;aACrD;SACF;KACF;IACD,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CACvB,CAAC,CAAC"}
|
package/dist/oxlintrc.json
CHANGED
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
{
|
|
14
14
|
"name": "import-js",
|
|
15
15
|
"specifier": "eslint-plugin-import"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "kamaal-imports",
|
|
19
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/consistent-inline-type-imports"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "kamaal-ternary",
|
|
23
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/no-nullish-check-first-ternary"
|
|
16
24
|
}
|
|
17
25
|
],
|
|
18
26
|
"options": {
|
|
@@ -45,6 +53,8 @@
|
|
|
45
53
|
"anti-slop/no-widen-then-assert": "error",
|
|
46
54
|
"anti-slop/require-readable-spacing": "error",
|
|
47
55
|
"anti-slop/require-safety-comment-for-type-assertion": "error",
|
|
56
|
+
"kamaal-imports/no-all-inline-type-imports": "error",
|
|
57
|
+
"kamaal-ternary/no-nullish-check-first-ternary": "error",
|
|
48
58
|
"curly": "error",
|
|
49
59
|
"typescript/no-deprecated": "error",
|
|
50
60
|
"typescript/consistent-type-imports": "error",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AstNode, RuleContext } from './rule-context.ts';
|
|
2
|
+
interface ImportSpecifierNode extends AstNode {
|
|
3
|
+
type: 'ImportSpecifier';
|
|
4
|
+
importKind?: 'type' | 'value';
|
|
5
|
+
imported: {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
local: {
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
interface ImportDeclarationNode extends AstNode {
|
|
13
|
+
type: 'ImportDeclaration';
|
|
14
|
+
importKind?: 'type' | 'value';
|
|
15
|
+
specifiers: (ImportSpecifierNode | {
|
|
16
|
+
type: 'ImportDefaultSpecifier' | 'ImportNamespaceSpecifier';
|
|
17
|
+
})[];
|
|
18
|
+
source: AstNode;
|
|
19
|
+
}
|
|
20
|
+
declare const _default: {
|
|
21
|
+
meta: {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
24
|
+
rules: {
|
|
25
|
+
'no-all-inline-type-imports': {
|
|
26
|
+
meta: {
|
|
27
|
+
fixable: string;
|
|
28
|
+
};
|
|
29
|
+
create(context: RuleContext): {
|
|
30
|
+
ImportDeclaration(node: ImportDeclarationNode): void;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export default _default;
|
|
36
|
+
//# sourceMappingURL=consistent-inline-type-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consistent-inline-type-imports.d.ts","sourceRoot":"","sources":["../../src/plugins/consistent-inline-type-imports.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE9D,UAAU,mBAAoB,SAAQ,OAAO;IAC3C,IAAI,EAAE,iBAAiB,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3B,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACzB;AAED,UAAU,qBAAsB,SAAQ,OAAO;IAC7C,IAAI,EAAE,mBAAmB,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,UAAU,EAAE,CAAC,mBAAmB,GAAG;QAAE,IAAI,EAAE,wBAAwB,GAAG,0BAA0B,CAAA;KAAE,CAAC,EAAE,CAAC;IACtG,MAAM,EAAE,OAAO,CAAC;CACjB;;IAOC,IAAI;QAAI,IAAI;;IACZ,KAAK;QACH,4BAA4B;YAC1B,IAAI;gBAAI,OAAO;;YACf,MAAM,UAAU,WAAW;gBAEvB,iBAAiB,OAAO,qBAAqB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Forbids `import { type A, type B } from 'x'` in favor of `import type { A, B } from 'x'`.
|
|
2
|
+
// Mixed imports such as `import { ok, type Result } from 'neverthrow'` are left untouched,
|
|
3
|
+
// since splitting those into two statements is not desired here.
|
|
4
|
+
function isImportSpecifier(specifier) {
|
|
5
|
+
return specifier.type === 'ImportSpecifier';
|
|
6
|
+
}
|
|
7
|
+
export default {
|
|
8
|
+
meta: { name: 'kamaal-imports' },
|
|
9
|
+
rules: {
|
|
10
|
+
'no-all-inline-type-imports': {
|
|
11
|
+
meta: { fixable: 'code' },
|
|
12
|
+
create(context) {
|
|
13
|
+
return {
|
|
14
|
+
ImportDeclaration(node) {
|
|
15
|
+
if (node.importKind === 'type') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const namedSpecifiers = node.specifiers.filter(isImportSpecifier);
|
|
19
|
+
if (namedSpecifiers.length === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const hasNonNamedSpecifiers = namedSpecifiers.length !== node.specifiers.length;
|
|
23
|
+
if (hasNonNamedSpecifiers) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const allInlineType = namedSpecifiers.every(specifier => specifier.importKind === 'type');
|
|
27
|
+
if (!allInlineType) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
context.report({
|
|
31
|
+
node,
|
|
32
|
+
message: 'Use a top-level `import type` instead of marking every named specifier with an inline `type` modifier.',
|
|
33
|
+
fix(fixer) {
|
|
34
|
+
const names = namedSpecifiers.map(specifier => specifier.imported.name === specifier.local.name
|
|
35
|
+
? specifier.imported.name
|
|
36
|
+
: `${specifier.imported.name} as ${specifier.local.name}`);
|
|
37
|
+
const sourceText = context.sourceCode.getText(node.source);
|
|
38
|
+
return fixer.replaceText(node, `import type { ${names.join(', ')} } from ${sourceText};`);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=consistent-inline-type-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consistent-inline-type-imports.js","sourceRoot":"","sources":["../../src/plugins/consistent-inline-type-imports.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2FAA2F;AAC3F,iEAAiE;AAkBjE,SAAS,iBAAiB,CAAC,SAAsD;IAC/E,OAAO,SAAS,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAC9C,CAAC;AAED,eAAe;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAChC,KAAK,EAAE;QACL,4BAA4B,EAAE;YAC5B,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;YACzB,MAAM,CAAC,OAAoB;gBACzB,OAAO;oBACL,iBAAiB,CAAC,IAA2B;wBAC3C,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;4BAC/B,OAAO;wBACT,CAAC;wBAED,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;wBAElE,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BACjC,OAAO;wBACT,CAAC;wBAED,MAAM,qBAAqB,GAAG,eAAe,CAAC,MAAM,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;wBAEhF,IAAI,qBAAqB,EAAE,CAAC;4BAC1B,OAAO;wBACT,CAAC;wBAED,MAAM,aAAa,GAAG,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC;wBAE1F,IAAI,CAAC,aAAa,EAAE,CAAC;4BACnB,OAAO;wBACT,CAAC;wBAED,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,OAAO,EACL,wGAAwG;4BAC1G,GAAG,CAAC,KAAK;gCACP,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAC5C,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,KAAK,CAAC,IAAI;oCAC9C,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI;oCACzB,CAAC,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAC5D,CAAC;gCAEF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gCAE3D,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,iBAAiB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,UAAU,GAAG,CAAC,CAAC;4BAC5F,CAAC;yBACF,CAAC,CAAC;oBACL,CAAC;iBACF,CAAC;YACJ,CAAC;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AstNode, RuleContext } from './rule-context.ts';
|
|
2
|
+
interface LiteralNode extends AstNode {
|
|
3
|
+
type: 'Literal';
|
|
4
|
+
value: null;
|
|
5
|
+
}
|
|
6
|
+
interface IdentifierNode extends AstNode {
|
|
7
|
+
type: 'Identifier';
|
|
8
|
+
name: 'undefined';
|
|
9
|
+
}
|
|
10
|
+
type ExpressionNode = LiteralNode | IdentifierNode | BinaryExpressionNode | LogicalExpressionNode | AstNode;
|
|
11
|
+
interface BinaryExpressionNode extends AstNode {
|
|
12
|
+
type: 'BinaryExpression';
|
|
13
|
+
operator: '==' | '===';
|
|
14
|
+
left: ExpressionNode;
|
|
15
|
+
right: ExpressionNode;
|
|
16
|
+
}
|
|
17
|
+
interface LogicalExpressionNode extends AstNode {
|
|
18
|
+
type: 'LogicalExpression';
|
|
19
|
+
operator: '||';
|
|
20
|
+
left: ExpressionNode;
|
|
21
|
+
right: ExpressionNode;
|
|
22
|
+
}
|
|
23
|
+
interface ConditionalExpressionNode extends AstNode {
|
|
24
|
+
type: 'ConditionalExpression';
|
|
25
|
+
test: ExpressionNode;
|
|
26
|
+
consequent: ExpressionNode;
|
|
27
|
+
alternate: ExpressionNode;
|
|
28
|
+
}
|
|
29
|
+
declare const _default: {
|
|
30
|
+
meta: {
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
rules: {
|
|
34
|
+
'no-nullish-check-first-ternary': {
|
|
35
|
+
meta: {
|
|
36
|
+
fixable: string;
|
|
37
|
+
};
|
|
38
|
+
create(context: RuleContext): {
|
|
39
|
+
ConditionalExpression(node: ConditionalExpressionNode): void;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export default _default;
|
|
45
|
+
//# sourceMappingURL=no-nullish-check-first-ternary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-nullish-check-first-ternary.d.ts","sourceRoot":"","sources":["../../src/plugins/no-nullish-check-first-ternary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE9D,UAAU,WAAY,SAAQ,OAAO;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;CACb;AAED,UAAU,cAAe,SAAQ,OAAO;IACtC,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,KAAK,cAAc,GAAG,WAAW,GAAG,cAAc,GAAG,oBAAoB,GAAG,qBAAqB,GAAG,OAAO,CAAC;AAE5G,UAAU,oBAAqB,SAAQ,OAAO;IAC5C,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC;IACvB,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,UAAU,qBAAsB,SAAQ,OAAO;IAC7C,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,IAAI,CAAC;IACf,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,UAAU,yBAA0B,SAAQ,OAAO;IACjD,IAAI,EAAE,uBAAuB,CAAC;IAC9B,IAAI,EAAE,cAAc,CAAC;IACrB,UAAU,EAAE,cAAc,CAAC;IAC3B,SAAS,EAAE,cAAc,CAAC;CAC3B;;IA6BC,IAAI;QAAI,IAAI;;IACZ,KAAK;QACH,gCAAgC;YAC9B,IAAI;gBAAI,OAAO;;YACf,MAAM,UAAU,WAAW;gBAEvB,qBAAqB,OAAO,yBAAyB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const EQUALITY_OPERATORS = { '==': '!=', '===': '!==' };
|
|
2
|
+
function isNullish(node) {
|
|
3
|
+
return ((node.type === 'Literal' && 'value' in node && node.value === null) ||
|
|
4
|
+
(node.type === 'Identifier' && 'name' in node && node.name === 'undefined'));
|
|
5
|
+
}
|
|
6
|
+
function isNullishEqualityCheck(node) {
|
|
7
|
+
return (node.type === 'BinaryExpression' &&
|
|
8
|
+
'left' in node &&
|
|
9
|
+
'right' in node &&
|
|
10
|
+
(isNullish(node.left) || isNullish(node.right)));
|
|
11
|
+
}
|
|
12
|
+
function flattenOrOperands(node) {
|
|
13
|
+
if (node.type !== 'LogicalExpression' || !('left' in node && 'right' in node)) {
|
|
14
|
+
return [node];
|
|
15
|
+
}
|
|
16
|
+
return flattenOrOperands(node.left).concat(flattenOrOperands(node.right));
|
|
17
|
+
}
|
|
18
|
+
export default {
|
|
19
|
+
meta: { name: 'kamaal-ternary' },
|
|
20
|
+
rules: {
|
|
21
|
+
'no-nullish-check-first-ternary': {
|
|
22
|
+
meta: { fixable: 'code' },
|
|
23
|
+
create(context) {
|
|
24
|
+
return {
|
|
25
|
+
ConditionalExpression(node) {
|
|
26
|
+
const checks = flattenOrOperands(node.test);
|
|
27
|
+
if (!checks.every(isNullishEqualityCheck) || !isNullish(node.consequent)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
context.report({
|
|
31
|
+
node,
|
|
32
|
+
message: 'Put the value-producing branch first: use `!= null`/`!== null`/`!== undefined` (joined with `&&` for multiple checks) and swap the branches instead of checking nullish first.',
|
|
33
|
+
fix(fixer) {
|
|
34
|
+
const flippedTest = checks
|
|
35
|
+
.map(check => {
|
|
36
|
+
const leftText = context.sourceCode.getText(check.left);
|
|
37
|
+
const rightText = context.sourceCode.getText(check.right);
|
|
38
|
+
return `${leftText} ${EQUALITY_OPERATORS[check.operator]} ${rightText}`;
|
|
39
|
+
})
|
|
40
|
+
.join(' && ');
|
|
41
|
+
const consequentText = context.sourceCode.getText(node.consequent);
|
|
42
|
+
const alternateText = context.sourceCode.getText(node.alternate);
|
|
43
|
+
return fixer.replaceText(node, `${flippedTest} ? ${alternateText} : ${consequentText}`);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=no-nullish-check-first-ternary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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Text(node: AstNode, text: string): AstNode;
|
|
6
|
+
}
|
|
7
|
+
interface SourceCode {
|
|
8
|
+
getText(node: AstNode): string;
|
|
9
|
+
}
|
|
10
|
+
export interface RuleContext {
|
|
11
|
+
sourceCode: SourceCode;
|
|
12
|
+
report(descriptor: {
|
|
13
|
+
node: AstNode;
|
|
14
|
+
message: string;
|
|
15
|
+
fix?: (fixer: RuleFixer) => AstNode;
|
|
16
|
+
}): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=rule-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-context.d.ts","sourceRoot":"","sources":["../../src/plugins/rule-context.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,SAAS;IACjB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACnD;AAED,UAAU,UAAU;IAClB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,CAAC,UAAU,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CACnG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-context.js","sourceRoot":"","sources":["../../src/plugins/rule-context.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamaal111/kamaal-quality-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Kamaal Farah's shared oxlint quality config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lint",
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"url": "git+https://github.com/kamaal111/kamaal-quality-config.git"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"src/plugins/consistent-inline-type-imports.ts",
|
|
20
|
+
"src/plugins/no-nullish-check-first-ternary.ts"
|
|
19
21
|
],
|
|
20
22
|
"type": "module",
|
|
21
23
|
"main": "./dist/index.js",
|
|
@@ -32,7 +34,9 @@
|
|
|
32
34
|
"./oxfmt": {
|
|
33
35
|
"types": "./dist/oxfmt.d.ts",
|
|
34
36
|
"default": "./dist/oxfmt.js"
|
|
35
|
-
}
|
|
37
|
+
},
|
|
38
|
+
"./plugins/consistent-inline-type-imports": "./src/plugins/consistent-inline-type-imports.ts",
|
|
39
|
+
"./plugins/no-nullish-check-first-ternary": "./src/plugins/no-nullish-check-first-ternary.ts"
|
|
36
40
|
},
|
|
37
41
|
"publishConfig": {
|
|
38
42
|
"access": "public"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Forbids `import { type A, type B } from 'x'` in favor of `import type { A, B } from 'x'`.
|
|
2
|
+
// Mixed imports such as `import { ok, type Result } from 'neverthrow'` are left untouched,
|
|
3
|
+
// since splitting those into two statements is not desired here.
|
|
4
|
+
|
|
5
|
+
import type { AstNode, RuleContext } from './rule-context.ts';
|
|
6
|
+
|
|
7
|
+
interface ImportSpecifierNode extends AstNode {
|
|
8
|
+
type: 'ImportSpecifier';
|
|
9
|
+
importKind?: 'type' | 'value';
|
|
10
|
+
imported: { name: string };
|
|
11
|
+
local: { name: string };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ImportDeclarationNode extends AstNode {
|
|
15
|
+
type: 'ImportDeclaration';
|
|
16
|
+
importKind?: 'type' | 'value';
|
|
17
|
+
specifiers: (ImportSpecifierNode | { type: 'ImportDefaultSpecifier' | 'ImportNamespaceSpecifier' })[];
|
|
18
|
+
source: AstNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isImportSpecifier(specifier: ImportDeclarationNode['specifiers'][number]): specifier is ImportSpecifierNode {
|
|
22
|
+
return specifier.type === 'ImportSpecifier';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
meta: { name: 'kamaal-imports' },
|
|
27
|
+
rules: {
|
|
28
|
+
'no-all-inline-type-imports': {
|
|
29
|
+
meta: { fixable: 'code' },
|
|
30
|
+
create(context: RuleContext) {
|
|
31
|
+
return {
|
|
32
|
+
ImportDeclaration(node: ImportDeclarationNode) {
|
|
33
|
+
if (node.importKind === 'type') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const namedSpecifiers = node.specifiers.filter(isImportSpecifier);
|
|
38
|
+
|
|
39
|
+
if (namedSpecifiers.length === 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const hasNonNamedSpecifiers = namedSpecifiers.length !== node.specifiers.length;
|
|
44
|
+
|
|
45
|
+
if (hasNonNamedSpecifiers) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const allInlineType = namedSpecifiers.every(specifier => specifier.importKind === 'type');
|
|
50
|
+
|
|
51
|
+
if (!allInlineType) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
context.report({
|
|
56
|
+
node,
|
|
57
|
+
message:
|
|
58
|
+
'Use a top-level `import type` instead of marking every named specifier with an inline `type` modifier.',
|
|
59
|
+
fix(fixer) {
|
|
60
|
+
const names = namedSpecifiers.map(specifier =>
|
|
61
|
+
specifier.imported.name === specifier.local.name
|
|
62
|
+
? specifier.imported.name
|
|
63
|
+
: `${specifier.imported.name} as ${specifier.local.name}`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const sourceText = context.sourceCode.getText(node.source);
|
|
67
|
+
|
|
68
|
+
return fixer.replaceText(node, `import type { ${names.join(', ')} } from ${sourceText};`);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { AstNode, RuleContext } from './rule-context.ts';
|
|
2
|
+
|
|
3
|
+
interface LiteralNode extends AstNode {
|
|
4
|
+
type: 'Literal';
|
|
5
|
+
value: null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface IdentifierNode extends AstNode {
|
|
9
|
+
type: 'Identifier';
|
|
10
|
+
name: 'undefined';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type ExpressionNode = LiteralNode | IdentifierNode | BinaryExpressionNode | LogicalExpressionNode | AstNode;
|
|
14
|
+
|
|
15
|
+
interface BinaryExpressionNode extends AstNode {
|
|
16
|
+
type: 'BinaryExpression';
|
|
17
|
+
operator: '==' | '===';
|
|
18
|
+
left: ExpressionNode;
|
|
19
|
+
right: ExpressionNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface LogicalExpressionNode extends AstNode {
|
|
23
|
+
type: 'LogicalExpression';
|
|
24
|
+
operator: '||';
|
|
25
|
+
left: ExpressionNode;
|
|
26
|
+
right: ExpressionNode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ConditionalExpressionNode extends AstNode {
|
|
30
|
+
type: 'ConditionalExpression';
|
|
31
|
+
test: ExpressionNode;
|
|
32
|
+
consequent: ExpressionNode;
|
|
33
|
+
alternate: ExpressionNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const EQUALITY_OPERATORS = { '==': '!=', '===': '!==' } as const;
|
|
37
|
+
|
|
38
|
+
function isNullish(node: ExpressionNode): node is LiteralNode | IdentifierNode {
|
|
39
|
+
return (
|
|
40
|
+
(node.type === 'Literal' && 'value' in node && node.value === null) ||
|
|
41
|
+
(node.type === 'Identifier' && 'name' in node && node.name === 'undefined')
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isNullishEqualityCheck(node: ExpressionNode): node is BinaryExpressionNode {
|
|
46
|
+
return (
|
|
47
|
+
node.type === 'BinaryExpression' &&
|
|
48
|
+
'left' in node &&
|
|
49
|
+
'right' in node &&
|
|
50
|
+
(isNullish(node.left) || isNullish(node.right))
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function flattenOrOperands(node: ExpressionNode): ExpressionNode[] {
|
|
55
|
+
if (node.type !== 'LogicalExpression' || !('left' in node && 'right' in node)) {
|
|
56
|
+
return [node];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return flattenOrOperands(node.left).concat(flattenOrOperands(node.right));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default {
|
|
63
|
+
meta: { name: 'kamaal-ternary' },
|
|
64
|
+
rules: {
|
|
65
|
+
'no-nullish-check-first-ternary': {
|
|
66
|
+
meta: { fixable: 'code' },
|
|
67
|
+
create(context: RuleContext) {
|
|
68
|
+
return {
|
|
69
|
+
ConditionalExpression(node: ConditionalExpressionNode) {
|
|
70
|
+
const checks = flattenOrOperands(node.test);
|
|
71
|
+
|
|
72
|
+
if (!checks.every(isNullishEqualityCheck) || !isNullish(node.consequent)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
context.report({
|
|
77
|
+
node,
|
|
78
|
+
message:
|
|
79
|
+
'Put the value-producing branch first: use `!= null`/`!== null`/`!== undefined` (joined with `&&` for multiple checks) and swap the branches instead of checking nullish first.',
|
|
80
|
+
fix(fixer) {
|
|
81
|
+
const flippedTest = checks
|
|
82
|
+
.map(check => {
|
|
83
|
+
const leftText = context.sourceCode.getText(check.left);
|
|
84
|
+
const rightText = context.sourceCode.getText(check.right);
|
|
85
|
+
|
|
86
|
+
return `${leftText} ${EQUALITY_OPERATORS[check.operator]} ${rightText}`;
|
|
87
|
+
})
|
|
88
|
+
.join(' && ');
|
|
89
|
+
|
|
90
|
+
const consequentText = context.sourceCode.getText(node.consequent);
|
|
91
|
+
|
|
92
|
+
const alternateText = context.sourceCode.getText(node.alternate);
|
|
93
|
+
|
|
94
|
+
return fixer.replaceText(node, `${flippedTest} ? ${alternateText} : ${consequentText}`);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|