@kamaal111/kamaal-quality-config 0.2.0 → 0.3.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.ts CHANGED
@@ -70,6 +70,7 @@ declare const _default: {
70
70
  allowInTypeGuards: boolean;
71
71
  }];
72
72
  'unicorn/no-abusive-eslint-disable': "error";
73
+ 'no-nested-ternary': "error";
73
74
  'import-js/order': ["error", {
74
75
  groups: (string | string[])[];
75
76
  'newlines-between': "always";
package/dist/oxlint.d.ts CHANGED
@@ -61,6 +61,7 @@ declare const _default: {
61
61
  allowInTypeGuards: boolean;
62
62
  }];
63
63
  'unicorn/no-abusive-eslint-disable': "error";
64
+ 'no-nested-ternary': "error";
64
65
  'import-js/order': ["error", {
65
66
  groups: (string | string[])[];
66
67
  'newlines-between': "always";
@@ -1 +1 @@
1
- {"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2FuB,KAAK;gBAAS,eAAe"}
1
+ {"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA4FuB,KAAK;gBAAS,eAAe"}
package/dist/oxlint.js CHANGED
@@ -72,6 +72,7 @@ export default defineConfig({
72
72
  'vitest/expect-expect': 'error',
73
73
  'anti-slop/no-runtime-typeof': ['error', { allowInTypeGuards: true }],
74
74
  'unicorn/no-abusive-eslint-disable': 'error',
75
+ 'no-nested-ternary': 'error',
75
76
  'import-js/order': [
76
77
  'error',
77
78
  {
@@ -1 +1 @@
1
- {"version":3,"file":"oxlint.js","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,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vitest/no-conditional-expect": "error",
109
109
  "vitest/expect-expect": "error",
110
110
  "unicorn/no-abusive-eslint-disable": "error",
111
+ "no-nested-ternary": "error",
111
112
  "import-js/order": [
112
113
  "error",
113
114
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamaal111/kamaal-quality-config",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Kamaal Farah's shared oxlint quality config.",
5
5
  "keywords": [
6
6
  "lint",
@@ -15,9 +15,7 @@
15
15
  "url": "git+https://github.com/kamaal111/kamaal-quality-config.git"
16
16
  },
17
17
  "files": [
18
- "dist",
19
- "src/plugins/consistent-inline-type-imports.ts",
20
- "src/plugins/no-nullish-check-first-ternary.ts"
18
+ "dist"
21
19
  ],
22
20
  "type": "module",
23
21
  "main": "./dist/index.js",
@@ -35,8 +33,8 @@
35
33
  "types": "./dist/oxfmt.d.ts",
36
34
  "default": "./dist/oxfmt.js"
37
35
  },
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
+ "./plugins/consistent-inline-type-imports": "./dist/plugins/consistent-inline-type-imports.js",
37
+ "./plugins/no-nullish-check-first-ternary": "./dist/plugins/no-nullish-check-first-ternary.js"
40
38
  },
41
39
  "publishConfig": {
42
40
  "access": "public"
@@ -73,7 +71,7 @@
73
71
  "scripts": {
74
72
  "build": "rm -rf dist && tsc -p tsconfig.build.json && node scripts/generate-json-config.ts",
75
73
  "clean:build": "rm -rf dist tsconfig.tsbuildinfo && pnpm run build",
76
- "lint": "oxlint",
74
+ "lint": "pnpm run build && oxlint",
77
75
  "format": "oxfmt",
78
76
  "format:check": "oxfmt --check",
79
77
  "type-check": "tsc --noEmit",
@@ -1,76 +0,0 @@
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
- };
@@ -1,102 +0,0 @@
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
- };