@siim-m/config 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +33 -2
- package/dist/anti-slop/LICENSE +21 -0
- package/dist/anti-slop/effect/baseline.d.ts +18 -0
- package/dist/anti-slop/effect/baseline.js +41 -0
- package/dist/anti-slop/effect/index.d.ts +3 -0
- package/dist/anti-slop/effect/index.js +16 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.js +39 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.d.ts +2 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.js +44 -0
- package/dist/anti-slop/effect/rules/no-service-parameters.d.ts +2 -0
- package/dist/anti-slop/effect/rules/no-service-parameters.js +181 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.d.ts +1 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.js +48 -0
- package/dist/anti-slop/effect/shared/tagged-values.d.ts +8 -0
- package/dist/anti-slop/effect/shared/tagged-values.js +68 -0
- package/dist/anti-slop/index.d.ts +3 -0
- package/dist/anti-slop/index.js +42 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.d.ts +2 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.js +60 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.d.ts +2 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.js +40 -0
- package/dist/anti-slop/rules/no-known-value-widening.d.ts +2 -0
- package/dist/anti-slop/rules/no-known-value-widening.js +300 -0
- package/dist/anti-slop/rules/no-module-mocking.d.ts +2 -0
- package/dist/anti-slop/rules/no-module-mocking.js +69 -0
- package/dist/anti-slop/rules/no-object-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-object-parameters.js +56 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.d.ts +2 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.js +99 -0
- package/dist/anti-slop/rules/no-reflect-apply.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-apply.js +25 -0
- package/dist/anti-slop/rules/no-reflect-get.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-get.js +25 -0
- package/dist/anti-slop/rules/no-runtime-typeof.d.ts +2 -0
- package/dist/anti-slop/rules/no-runtime-typeof.js +64 -0
- package/dist/anti-slop/rules/no-unknown-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-parameters.js +51 -0
- package/dist/anti-slop/rules/no-unknown-returns.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-returns.js +58 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.js +40 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.d.ts +2 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.js +134 -0
- package/dist/anti-slop/rules/no-widen-then-assert.d.ts +2 -0
- package/dist/anti-slop/rules/no-widen-then-assert.js +270 -0
- package/dist/anti-slop/rules/require-pascal-case-namespace-imports.d.ts +8 -0
- package/dist/anti-slop/rules/require-pascal-case-namespace-imports.js +36 -0
- package/dist/anti-slop/rules/require-readable-spacing.d.ts +3 -0
- package/dist/anti-slop/rules/require-readable-spacing.js +65 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.js +100 -0
- package/dist/anti-slop/shared/array-method.d.ts +12 -0
- package/dist/anti-slop/shared/array-method.js +84 -0
- package/dist/anti-slop/shared/dictionary-types.d.ts +20 -0
- package/dist/anti-slop/shared/dictionary-types.js +377 -0
- package/dist/anti-slop/shared/function-parameters.d.ts +8 -0
- package/dist/anti-slop/shared/function-parameters.js +40 -0
- package/dist/anti-slop/shared/lexical-type-parameters.d.ts +5 -0
- package/dist/anti-slop/shared/lexical-type-parameters.js +47 -0
- package/dist/anti-slop/shared/reflect-method.d.ts +3 -0
- package/dist/anti-slop/shared/reflect-method.js +20 -0
- package/dist/anti-slop/shared/scope.d.ts +3 -0
- package/dist/anti-slop/shared/scope.js +11 -0
- package/dist/anti-slop/shared/type-alias-resolution.d.ts +23 -0
- package/dist/anti-slop/shared/type-alias-resolution.js +162 -0
- package/dist/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.d.ts +27 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.js +28 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.d.ts +37 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.js +703 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-options.d.ts +87 -0
- package/dist/oxfmt.d.ts +27 -0
- package/dist/oxfmt.js +19 -0
- package/dist/oxlint.d.ts +44 -0
- package/dist/oxlint.js +44 -0
- package/package.json +60 -4
- package/reset.d.ts +4 -0
- package/tsconfig.base.json +148 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 siim-m
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @siim-m/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared oxlint, oxfmt and tsconfig settings for TypeScript, with the
|
|
4
|
+
[anti-slop](https://github.com/dmmulroy/anti-slop) oxlint rules.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
bun add -d @siim-m/config oxlint oxlint-tsgolint oxfmt
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// oxlint.config.mts
|
|
12
|
+
import base from '@siim-m/config/oxlint';
|
|
13
|
+
import { defineConfig } from 'oxlint';
|
|
14
|
+
|
|
15
|
+
export default defineConfig({ extends: [base], rules: { 'anti-slop/no-runtime-typeof': 'off' } });
|
|
16
|
+
|
|
17
|
+
// oxfmt.config.mts
|
|
18
|
+
import base from '@siim-m/config/oxfmt';
|
|
19
|
+
|
|
20
|
+
export default { ...base, singleQuote: false };
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{ "extends": "@siim-m/config/tsconfig.json" }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Every rule is on at `error`; a project turns off what it can't pass yet. Run oxlint with
|
|
28
|
+
`--type-aware`. For ts-reset's stricter built-in types, add `import '@siim-m/config/reset.d.ts';` to
|
|
29
|
+
a `.d.ts` file in the project.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
MIT. The anti-slop rules are MIT, copyright Dillon Mulroy; `require-readable-spacing` uses MIT code
|
|
34
|
+
from ESLint Stylistic.
|
|
@@ -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,18 @@
|
|
|
1
|
+
import type { Context, ESTree } from '@oxlint/plugins';
|
|
2
|
+
/** Schema of the `baseline` option: a rule's pre-existing violations, listed by name. */
|
|
3
|
+
export declare const baselineOption: {
|
|
4
|
+
readonly description: 'Pre-existing violations, as `<repo-relative path>#<name>`.';
|
|
5
|
+
readonly type: 'array';
|
|
6
|
+
readonly items: {
|
|
7
|
+
readonly type: 'string';
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const staleBaselineMessage = "Baseline entry \"{{entry}}\" no longer matches a violation. Remove it from the rule options in the oxlint config.";
|
|
11
|
+
/**
|
|
12
|
+
* Track the baseline entries for the file being linted. `allows` consumes a match;
|
|
13
|
+
* `reportStale` reports the entries no violation used, so the list only shrinks.
|
|
14
|
+
*/
|
|
15
|
+
export declare function fileBaseline(context: Context): {
|
|
16
|
+
allows: (name: string) => boolean;
|
|
17
|
+
reportStale: (program: ESTree.Program) => void;
|
|
18
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Schema of the `baseline` option: a rule's pre-existing violations, listed by name. */
|
|
2
|
+
export const baselineOption = {
|
|
3
|
+
description: 'Pre-existing violations, as `<repo-relative path>#<name>`.',
|
|
4
|
+
type: 'array',
|
|
5
|
+
items: { type: 'string' },
|
|
6
|
+
};
|
|
7
|
+
export const staleBaselineMessage = 'Baseline entry "{{entry}}" no longer matches a violation. Remove it from the rule options in the oxlint config.';
|
|
8
|
+
/**
|
|
9
|
+
* Track the baseline entries for the file being linted. `allows` consumes a match;
|
|
10
|
+
* `reportStale` reports the entries no violation used, so the list only shrinks.
|
|
11
|
+
*/
|
|
12
|
+
export function fileBaseline(context) {
|
|
13
|
+
const [option] = context.options;
|
|
14
|
+
const entries = typeof option === 'object' && option !== null && 'baseline' in option ? option.baseline : [];
|
|
15
|
+
const root = `${context.cwd.replaceAll('\\', '/')}/`;
|
|
16
|
+
const absolute = context.physicalFilename.replaceAll('\\', '/');
|
|
17
|
+
const file = absolute.startsWith(root) ? absolute.slice(root.length) : absolute;
|
|
18
|
+
const unused = new Set((Array.isArray(entries) ? entries : [])
|
|
19
|
+
.filter((entry) => typeof entry === 'string')
|
|
20
|
+
.filter((entry) => entry.startsWith(`${file}#`))
|
|
21
|
+
.map((entry) => entry.slice(file.length + 1)));
|
|
22
|
+
const used = new Set();
|
|
23
|
+
return {
|
|
24
|
+
allows: (name) => {
|
|
25
|
+
if (!unused.has(name) && !used.has(name))
|
|
26
|
+
return false;
|
|
27
|
+
unused.delete(name);
|
|
28
|
+
used.add(name);
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
reportStale: (program) => {
|
|
32
|
+
for (const name of unused) {
|
|
33
|
+
context.report({
|
|
34
|
+
node: program,
|
|
35
|
+
messageId: 'staleBaseline',
|
|
36
|
+
data: { entry: `${file}#${name}` },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
import { noManualEffectErrorTagRule } from "./rules/no-manual-effect-error-tag.js";
|
|
3
|
+
import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.js";
|
|
4
|
+
import { noServiceParametersRule } from "./rules/no-service-parameters.js";
|
|
5
|
+
import { preferEffectMatchRule } from "./rules/prefer-effect-match.js";
|
|
6
|
+
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
7
|
+
const antiSlopEffectPlugin = eslintCompatPlugin({
|
|
8
|
+
meta: { name: "anti-slop-effect" },
|
|
9
|
+
rules: {
|
|
10
|
+
"no-manual-effect-error-tag": noManualEffectErrorTagRule,
|
|
11
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
12
|
+
"no-service-parameters": noServiceParametersRule,
|
|
13
|
+
"prefer-effect-match": preferEffectMatchRule,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
export default antiSlopEffectPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noManualEffectErrorTagRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isInsideBroadEffectHandler, isReasonTagMember, isTagMember, tagMemberFromComparison, } from "../shared/tagged-values.js";
|
|
3
|
+
export const noManualEffectErrorTagRule = defineRule({
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler.",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
|
|
11
|
+
reason: "Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
createOnce(context) {
|
|
15
|
+
return {
|
|
16
|
+
BinaryExpression(node) {
|
|
17
|
+
const tagMember = tagMemberFromComparison(node);
|
|
18
|
+
if (tagMember === undefined ||
|
|
19
|
+
!isInsideBroadEffectHandler(node)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
context.report({
|
|
23
|
+
node,
|
|
24
|
+
messageId: isReasonTagMember(tagMember) ? "reason" : "tag",
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
SwitchStatement(node) {
|
|
28
|
+
if (!isTagMember(node.discriminant) ||
|
|
29
|
+
!isInsideBroadEffectHandler(node)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
context.report({
|
|
33
|
+
node,
|
|
34
|
+
messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag",
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
3
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
4
|
+
function isProjectLocalImport(source) {
|
|
5
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
6
|
+
}
|
|
7
|
+
function getImportedName(specifier) {
|
|
8
|
+
if (specifier.imported.type === "Identifier")
|
|
9
|
+
return specifier.imported.name;
|
|
10
|
+
return specifier.imported.value;
|
|
11
|
+
}
|
|
12
|
+
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
13
|
+
export const noServiceConstructorImportsRule = defineRule({
|
|
14
|
+
meta: {
|
|
15
|
+
type: "problem",
|
|
16
|
+
docs: {
|
|
17
|
+
description: "Disallow project-local make<CapabilityName> imports outside test and spec files.",
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
serviceConstructorImport: 'Do not import Effect service constructor "{{name}}" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root.',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
25
|
+
return {
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
if (isTestFile || !isProjectLocalImport(node.source.value))
|
|
28
|
+
return;
|
|
29
|
+
for (const specifier of node.specifiers) {
|
|
30
|
+
if (specifier.type !== "ImportSpecifier")
|
|
31
|
+
continue;
|
|
32
|
+
const importedName = getImportedName(specifier);
|
|
33
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName))
|
|
34
|
+
continue;
|
|
35
|
+
context.report({
|
|
36
|
+
node: specifier,
|
|
37
|
+
messageId: "serviceConstructorImport",
|
|
38
|
+
data: { name: importedName },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { defineRule } from '@oxlint/plugins';
|
|
2
|
+
import { functionParameterBindingName, functionParameterTypeAnnotation, } from '../../shared/function-parameters.js';
|
|
3
|
+
import { baselineOption, fileBaseline, staleBaselineMessage } from '../baseline.js';
|
|
4
|
+
/** Services callers may hand along, such as request-scoped context, from the `exempt` option. */
|
|
5
|
+
function exemptServices(option) {
|
|
6
|
+
if (typeof option !== 'object' || option === null || !('exempt' in option))
|
|
7
|
+
return new Set();
|
|
8
|
+
const exempt = option.exempt;
|
|
9
|
+
if (!Array.isArray(exempt))
|
|
10
|
+
return new Set();
|
|
11
|
+
return new Set(exempt.filter((service) => typeof service === 'string'));
|
|
12
|
+
}
|
|
13
|
+
function typeNameText(name) {
|
|
14
|
+
if (name.type === 'Identifier')
|
|
15
|
+
return name.name;
|
|
16
|
+
if (name.type === 'ThisExpression')
|
|
17
|
+
return 'this';
|
|
18
|
+
return `${typeNameText(name.left)}.${name.right.name}`;
|
|
19
|
+
}
|
|
20
|
+
function typeQueryText(type) {
|
|
21
|
+
if (type?.type !== 'TSTypeQuery' || type.exprName.type === 'TSImportType')
|
|
22
|
+
return undefined;
|
|
23
|
+
return typeNameText(type.exprName);
|
|
24
|
+
}
|
|
25
|
+
/** `Context.Service<Self, Shape>()('id')`: the local shape declarations a service class names. */
|
|
26
|
+
function serviceShapeName(node) {
|
|
27
|
+
let callee = node.superClass;
|
|
28
|
+
while (callee?.type === 'CallExpression') {
|
|
29
|
+
const shape = callee.typeArguments?.params[1];
|
|
30
|
+
if (shape?.type === 'TSTypeReference' && shape.typeName.type === 'Identifier') {
|
|
31
|
+
return shape.typeName.name;
|
|
32
|
+
}
|
|
33
|
+
callee = callee.callee;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function collectTypeDeclarations(program) {
|
|
38
|
+
const declarations = new Map();
|
|
39
|
+
const imported = new Set();
|
|
40
|
+
for (const statement of program.body) {
|
|
41
|
+
if (statement.type === 'ImportDeclaration') {
|
|
42
|
+
for (const specifier of statement.specifiers)
|
|
43
|
+
imported.add(specifier.local.name);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;
|
|
47
|
+
if (declaration?.type === 'TSTypeAliasDeclaration') {
|
|
48
|
+
declarations.set(declaration.id.name, declaration.typeAnnotation);
|
|
49
|
+
}
|
|
50
|
+
if (declaration?.type === 'ClassDeclaration' && declaration.id) {
|
|
51
|
+
const shape = serviceShapeName(declaration);
|
|
52
|
+
if (shape !== undefined)
|
|
53
|
+
declarations.set(shape, { service: declaration.id.name });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { declarations, imported };
|
|
57
|
+
}
|
|
58
|
+
/** The service whose instance (or member) `type` describes, if any. */
|
|
59
|
+
function serviceOfType(type, declarations, imported, seen = new Set()) {
|
|
60
|
+
switch (type.type) {
|
|
61
|
+
case 'TSParenthesizedType':
|
|
62
|
+
return serviceOfType(type.typeAnnotation, declarations, imported, seen);
|
|
63
|
+
case 'TSUnionType':
|
|
64
|
+
for (const member of type.types) {
|
|
65
|
+
const service = serviceOfType(member, declarations, imported, seen);
|
|
66
|
+
if (service !== undefined)
|
|
67
|
+
return service;
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
case 'TSIndexedAccessType': {
|
|
71
|
+
// `X['Service']` is the instance; `X['Service']['method']` is one of its members.
|
|
72
|
+
const index = type.indexType;
|
|
73
|
+
if (index.type === 'TSLiteralType' && index.literal.type === 'Literal') {
|
|
74
|
+
if (index.literal.value === 'Service') {
|
|
75
|
+
if (type.objectType.type === 'TSTypeReference')
|
|
76
|
+
return typeNameText(type.objectType.typeName);
|
|
77
|
+
return typeQueryText(type.objectType);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return serviceOfType(type.objectType, declarations, imported, seen);
|
|
81
|
+
}
|
|
82
|
+
case 'TSTypeReference': {
|
|
83
|
+
const name = typeNameText(type.typeName);
|
|
84
|
+
const [argument] = type.typeArguments?.params ?? [];
|
|
85
|
+
if (name.endsWith('Service.Shape'))
|
|
86
|
+
return typeQueryText(argument);
|
|
87
|
+
if (name === 'Effect.Success') {
|
|
88
|
+
// `Effect.Success<typeof Tag>` or `Effect.Success<typeof Tag.make>`
|
|
89
|
+
const query = typeQueryText(argument)?.replace(/\.make$/u, '');
|
|
90
|
+
return query !== undefined && /^[A-Z]\w*$/u.test(query) ? query : undefined;
|
|
91
|
+
}
|
|
92
|
+
if (type.typeName.type !== 'Identifier' || seen.has(name))
|
|
93
|
+
return undefined;
|
|
94
|
+
const declaration = declarations.get(name);
|
|
95
|
+
if (declaration !== undefined && 'service' in declaration)
|
|
96
|
+
return declaration.service;
|
|
97
|
+
if (declaration !== undefined) {
|
|
98
|
+
return serviceOfType(declaration, declarations, imported, new Set([...seen, name]));
|
|
99
|
+
}
|
|
100
|
+
// Service shapes declared in another module follow the `<Service>Shape` naming.
|
|
101
|
+
if (imported.has(name) && name.endsWith('Shape'))
|
|
102
|
+
return name.slice(0, -'Shape'.length);
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** The binding a function is declared or assigned to, for baseline entries. */
|
|
110
|
+
function functionName(node) {
|
|
111
|
+
if (node.type !== 'ArrowFunctionExpression' && node.id)
|
|
112
|
+
return node.id.name;
|
|
113
|
+
let current = node.parent;
|
|
114
|
+
while (current.type === 'CallExpression' || current.type === 'TSAsExpression') {
|
|
115
|
+
current = current.parent;
|
|
116
|
+
}
|
|
117
|
+
if (current.type === 'VariableDeclarator' && current.id.type === 'Identifier') {
|
|
118
|
+
return current.id.name;
|
|
119
|
+
}
|
|
120
|
+
if ((current.type === 'MethodDefinition' || current.type === 'Property') &&
|
|
121
|
+
current.key.type === 'Identifier') {
|
|
122
|
+
return current.key.name;
|
|
123
|
+
}
|
|
124
|
+
return '<anonymous>';
|
|
125
|
+
}
|
|
126
|
+
/** Keep service instances out of function signatures; methods use dependencies captured at construction. */
|
|
127
|
+
export const noServiceParametersRule = defineRule({
|
|
128
|
+
meta: {
|
|
129
|
+
type: 'problem',
|
|
130
|
+
docs: {
|
|
131
|
+
description: 'Disallow function parameters typed as an Effect service instance.',
|
|
132
|
+
},
|
|
133
|
+
messages: {
|
|
134
|
+
serviceParameter: 'Parameter "{{parameter}}" takes the {{service}} service from the caller. Do not pass service instances as function arguments: acquire services from context during Context.Service, layer, or RPC handler layer construction, and use the captured dependency.',
|
|
135
|
+
staleBaseline: staleBaselineMessage,
|
|
136
|
+
},
|
|
137
|
+
schema: [
|
|
138
|
+
{
|
|
139
|
+
type: 'object',
|
|
140
|
+
properties: {
|
|
141
|
+
baseline: baselineOption,
|
|
142
|
+
exempt: {
|
|
143
|
+
description: 'Services callers may pass along, such as request-scoped context, by class name.',
|
|
144
|
+
type: 'array',
|
|
145
|
+
items: { type: 'string' },
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
additionalProperties: false,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
create(context) {
|
|
153
|
+
const { declarations, imported } = collectTypeDeclarations(context.sourceCode.ast);
|
|
154
|
+
const baseline = fileBaseline(context);
|
|
155
|
+
const exempt = exemptServices(context.options[0]);
|
|
156
|
+
const checkParameters = (node) => {
|
|
157
|
+
for (const parameter of node.params) {
|
|
158
|
+
const annotation = functionParameterTypeAnnotation(parameter);
|
|
159
|
+
if (annotation == null)
|
|
160
|
+
continue;
|
|
161
|
+
const service = serviceOfType(annotation.typeAnnotation, declarations, imported);
|
|
162
|
+
if (service === undefined || exempt.has(service))
|
|
163
|
+
continue;
|
|
164
|
+
const name = functionParameterBindingName(parameter, context.sourceCode);
|
|
165
|
+
if (baseline.allows(`${functionName(node)}.${name}`))
|
|
166
|
+
continue;
|
|
167
|
+
context.report({
|
|
168
|
+
node: parameter,
|
|
169
|
+
messageId: 'serviceParameter',
|
|
170
|
+
data: { parameter: name, service },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
FunctionDeclaration: checkParameters,
|
|
176
|
+
FunctionExpression: checkParameters,
|
|
177
|
+
ArrowFunctionExpression: checkParameters,
|
|
178
|
+
'Program:exit': baseline.reportStale,
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const preferEffectMatchRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const equalityOperators = new Set(["==", "===", "!=", "!=="]);
|
|
3
|
+
export const preferEffectMatchRule = defineRule({
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Use Match from Effect for chained literal ternaries over the same value.",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
preferMatch: "Use Match from Effect instead of a chained literal ternary.",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
const isLiteral = (node) => node.type === "Literal" ||
|
|
15
|
+
(node.type === "TemplateLiteral" && node.expressions.length === 0);
|
|
16
|
+
const comparedValue = (node) => {
|
|
17
|
+
if (node.type !== "BinaryExpression" ||
|
|
18
|
+
!equalityOperators.has(node.operator)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (isLiteral(node.left))
|
|
22
|
+
return context.sourceCode.getText(node.right);
|
|
23
|
+
if (isLiteral(node.right))
|
|
24
|
+
return context.sourceCode.getText(node.left);
|
|
25
|
+
return undefined;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
ConditionalExpression(node) {
|
|
29
|
+
if (node.parent?.type === "ConditionalExpression")
|
|
30
|
+
return;
|
|
31
|
+
const value = comparedValue(node.test);
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return;
|
|
34
|
+
let alternate = node.alternate;
|
|
35
|
+
let literalChecks = 1;
|
|
36
|
+
while (alternate.type === "ConditionalExpression") {
|
|
37
|
+
if (comparedValue(alternate.test) !== value)
|
|
38
|
+
return;
|
|
39
|
+
literalChecks += 1;
|
|
40
|
+
alternate = alternate.alternate;
|
|
41
|
+
}
|
|
42
|
+
if (literalChecks > 1) {
|
|
43
|
+
context.report({ node, messageId: "preferMatch" });
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
2
|
+
export declare const isStringLiteral: (node: ESTree.Node | null | undefined) => node is ESTree.StringLiteral;
|
|
3
|
+
export declare const isTagMember: (node: ESTree.Node | null | undefined) => node is ESTree.MemberExpression;
|
|
4
|
+
export declare const tagMemberFromComparison: (node: ESTree.BinaryExpression) => ESTree.MemberExpression | undefined;
|
|
5
|
+
export declare const isInsideBroadEffectHandler: (node: ESTree.Node) => boolean;
|
|
6
|
+
export declare const isReasonTagMember: (node: ESTree.MemberExpression) => boolean;
|
|
7
|
+
export declare const propertyName: (property: ESTree.ObjectProperty) => string | undefined;
|
|
8
|
+
export declare const isMatchPatternObject: (node: ESTree.ObjectExpression) => boolean;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const equalityOperators = new Set(["==", "===", "!=", "!=="]);
|
|
2
|
+
const broadEffectCatchMethods = new Set(["catch", "catchAll", "catchIf"]);
|
|
3
|
+
export const isStringLiteral = (node) => node?.type === "Literal" && typeof node.value === "string";
|
|
4
|
+
export const isTagMember = (node) => node?.type === "MemberExpression" &&
|
|
5
|
+
((!node.computed &&
|
|
6
|
+
node.property.type === "Identifier" &&
|
|
7
|
+
node.property.name === "_tag") ||
|
|
8
|
+
(node.computed &&
|
|
9
|
+
isStringLiteral(node.property) &&
|
|
10
|
+
node.property.value === "_tag"));
|
|
11
|
+
export const tagMemberFromComparison = (node) => {
|
|
12
|
+
if (!equalityOperators.has(node.operator))
|
|
13
|
+
return undefined;
|
|
14
|
+
if (isTagMember(node.left) && isStringLiteral(node.right))
|
|
15
|
+
return node.left;
|
|
16
|
+
if (isTagMember(node.right) && isStringLiteral(node.left))
|
|
17
|
+
return node.right;
|
|
18
|
+
return undefined;
|
|
19
|
+
};
|
|
20
|
+
const isBroadEffectCatchCall = (node) => node?.type === "CallExpression" &&
|
|
21
|
+
node.callee.type === "MemberExpression" &&
|
|
22
|
+
node.callee.object.type === "Identifier" &&
|
|
23
|
+
node.callee.object.name === "Effect" &&
|
|
24
|
+
!node.callee.computed &&
|
|
25
|
+
node.callee.property.type === "Identifier" &&
|
|
26
|
+
broadEffectCatchMethods.has(node.callee.property.name);
|
|
27
|
+
export const isInsideBroadEffectHandler = (node) => {
|
|
28
|
+
let current = node.parent;
|
|
29
|
+
while (current !== null && current !== undefined) {
|
|
30
|
+
if (current.type === "ArrowFunctionExpression" ||
|
|
31
|
+
current.type === "FunctionExpression") {
|
|
32
|
+
return (isBroadEffectCatchCall(current.parent) &&
|
|
33
|
+
current.parent.arguments.includes(current));
|
|
34
|
+
}
|
|
35
|
+
current = current.parent;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
export const isReasonTagMember = (node) => node.object.type === "MemberExpression" &&
|
|
40
|
+
((!node.object.computed &&
|
|
41
|
+
node.object.property.type === "Identifier" &&
|
|
42
|
+
node.object.property.name === "reason") ||
|
|
43
|
+
(node.object.computed &&
|
|
44
|
+
isStringLiteral(node.object.property) &&
|
|
45
|
+
node.object.property.value === "reason"));
|
|
46
|
+
export const propertyName = (property) => {
|
|
47
|
+
if (!property.computed && property.key.type === "Identifier") {
|
|
48
|
+
return property.key.name;
|
|
49
|
+
}
|
|
50
|
+
if (property.key.type === "Literal" &&
|
|
51
|
+
typeof property.key.value === "string") {
|
|
52
|
+
return property.key.value;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
};
|
|
56
|
+
export const isMatchPatternObject = (node) => {
|
|
57
|
+
const call = node.parent;
|
|
58
|
+
if (call?.type !== "CallExpression" || !call.arguments.includes(node)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const callee = call.callee;
|
|
62
|
+
return (callee.type === "MemberExpression" &&
|
|
63
|
+
callee.object.type === "Identifier" &&
|
|
64
|
+
callee.object.name === "Match" &&
|
|
65
|
+
!callee.computed &&
|
|
66
|
+
callee.property.type === "Identifier" &&
|
|
67
|
+
(callee.property.name === "when" || callee.property.name === "not"));
|
|
68
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
import { noReduceAccumulatorCopyRule } from "./rules/no-reduce-accumulator-copy.js";
|
|
3
|
+
import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.js";
|
|
4
|
+
import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.js";
|
|
5
|
+
import { noKnownValueWideningRule } from "./rules/no-known-value-widening.js";
|
|
6
|
+
import { noModuleMockingRule } from "./rules/no-module-mocking.js";
|
|
7
|
+
import { noObjectParametersRule } from "./rules/no-object-parameters.js";
|
|
8
|
+
import { noReflectApplyRule } from "./rules/no-reflect-apply.js";
|
|
9
|
+
import { noReflectGetRule } from "./rules/no-reflect-get.js";
|
|
10
|
+
import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.js";
|
|
11
|
+
import { noUnknownParametersRule } from "./rules/no-unknown-parameters.js";
|
|
12
|
+
import { noUnknownReturnsRule } from "./rules/no-unknown-returns.js";
|
|
13
|
+
import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.js";
|
|
14
|
+
import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.js";
|
|
15
|
+
import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.js";
|
|
16
|
+
import { requirePascalCaseNamespaceImportsRule } from "./rules/require-pascal-case-namespace-imports.js";
|
|
17
|
+
import { requireReadableSpacingRule } from "./rules/require-readable-spacing.js";
|
|
18
|
+
import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.js";
|
|
19
|
+
/** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
|
|
20
|
+
const antiSlopPlugin = eslintCompatPlugin({
|
|
21
|
+
meta: { name: "anti-slop" },
|
|
22
|
+
rules: {
|
|
23
|
+
"no-reduce-accumulator-copy": noReduceAccumulatorCopyRule,
|
|
24
|
+
"no-chained-type-assertions": noChainedTypeAssertionsRule,
|
|
25
|
+
"no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
|
|
26
|
+
"no-known-value-widening": noKnownValueWideningRule,
|
|
27
|
+
"no-module-mocking": noModuleMockingRule,
|
|
28
|
+
"no-object-parameters": noObjectParametersRule,
|
|
29
|
+
"no-reflect-apply": noReflectApplyRule,
|
|
30
|
+
"no-reflect-get": noReflectGetRule,
|
|
31
|
+
"no-runtime-typeof": noRuntimeTypeofRule,
|
|
32
|
+
"no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
|
|
33
|
+
"no-unknown-parameters": noUnknownParametersRule,
|
|
34
|
+
"no-unknown-returns": noUnknownReturnsRule,
|
|
35
|
+
"no-unknown-type-aliases": noUnknownTypeAliasesRule,
|
|
36
|
+
"no-widen-then-assert": noWidenThenAssertRule,
|
|
37
|
+
"require-pascal-case-namespace-imports": requirePascalCaseNamespaceImportsRule,
|
|
38
|
+
"require-readable-spacing": requireReadableSpacingRule,
|
|
39
|
+
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
export default antiSlopPlugin;
|