@dvukovic/style-guide 0.15.0 → 0.17.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 +2 -0
- package/dist/cli/prompts.d.ts +1 -1
- package/dist/eslint/rules/no-instanceof-error/no-instanceof-error.d.ts +16 -0
- package/package.json +1 -1
- package/src/cli/generators/eslint.js +12 -0
- package/src/cli/generators/scripts.js +2 -0
- package/src/cli/prompts.js +2 -0
- package/src/cspell/base.txt +1 -0
- package/src/eslint/plugins/dvukovic.js +3 -0
- package/src/eslint/rules/no-instanceof-error/no-instanceof-error.js +36 -0
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ export default customDefineConfig({
|
|
|
47
47
|
- `playwright()` - Playwright e2e testing
|
|
48
48
|
- `mobx()` - MobX state management
|
|
49
49
|
- `storybook()` - Storybook
|
|
50
|
+
- `tanstackQuery()` - TanStack Query
|
|
51
|
+
- `turbo()` - Turborepo
|
|
50
52
|
- `packageJson()` - package.json linting
|
|
51
53
|
- `packageJsonWorkspace()` - package.json linting for monorepos
|
|
52
54
|
|
package/dist/cli/prompts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function promptToolSelection(): Promise<string[]>;
|
|
2
2
|
export function promptESLintOptions(): Promise<{
|
|
3
|
-
extras: ("mobx" | "storybook")[];
|
|
3
|
+
extras: ("mobx" | "storybook" | "tanstackQuery" | "turbo")[];
|
|
4
4
|
framework: "none" | "react" | "next";
|
|
5
5
|
includeAws: boolean;
|
|
6
6
|
includeNode: boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export namespace noInstanceofError {
|
|
2
|
+
function create(context: any): {
|
|
3
|
+
BinaryExpression(node: any): void;
|
|
4
|
+
};
|
|
5
|
+
namespace meta {
|
|
6
|
+
namespace docs {
|
|
7
|
+
let description: string;
|
|
8
|
+
}
|
|
9
|
+
let fixable: string;
|
|
10
|
+
namespace messages {
|
|
11
|
+
let forbidden: string;
|
|
12
|
+
}
|
|
13
|
+
let schema: never[];
|
|
14
|
+
let type: string;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -31,6 +31,8 @@ export function generateESLintConfig(options) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
if (framework === "next") {
|
|
34
|
+
imports.push("react")
|
|
35
|
+
configs.push("react()")
|
|
34
36
|
imports.push("next")
|
|
35
37
|
configs.push("next()")
|
|
36
38
|
ignores.push("out")
|
|
@@ -81,6 +83,16 @@ export function generateESLintConfig(options) {
|
|
|
81
83
|
configs.push("storybook()")
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
if (extras.includes("tanstackQuery")) {
|
|
87
|
+
imports.push("tanstackQuery")
|
|
88
|
+
configs.push("tanstackQuery()")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (extras.includes("turbo")) {
|
|
92
|
+
imports.push("turbo")
|
|
93
|
+
configs.push("turbo()")
|
|
94
|
+
}
|
|
95
|
+
|
|
84
96
|
if (isMonorepo) {
|
|
85
97
|
imports.push("packageJsonWorkspace")
|
|
86
98
|
configs.push("packageJsonWorkspace()")
|
|
@@ -26,11 +26,13 @@ export function generateScripts(tools, packageManager) {
|
|
|
26
26
|
if (tools.includes("cspell")) {
|
|
27
27
|
scripts["lint:cspell"] = "cspell --no-progress --no-summary --unique '**'"
|
|
28
28
|
lintParts.push(`${runner} lint:cspell`)
|
|
29
|
+
fixParts.push(`${runner} lint:cspell`)
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
if (tools.includes("knip")) {
|
|
32
33
|
scripts["lint:knip"] = "knip --cache"
|
|
33
34
|
lintParts.push(`${runner} lint:knip`)
|
|
35
|
+
fixParts.push(`${runner} lint:knip`)
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
if (lintParts.length > 0) {
|
package/src/cli/prompts.js
CHANGED
|
@@ -147,6 +147,8 @@ export async function promptESLintOptions() {
|
|
|
147
147
|
options: [
|
|
148
148
|
{ label: "MobX", value: "mobx" },
|
|
149
149
|
{ label: "Storybook", value: "storybook" },
|
|
150
|
+
{ label: "TanStack Query", value: "tanstackQuery" },
|
|
151
|
+
{ label: "Turbo", value: "turbo" },
|
|
150
152
|
],
|
|
151
153
|
required: false,
|
|
152
154
|
})
|
package/src/cspell/base.txt
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { documentTodos } from "../rules/document-todos/document-todos.js"
|
|
2
2
|
import { noCommentedOutCode } from "../rules/no-commented-out-code/no-commented-out-code.js"
|
|
3
|
+
import { noInstanceofError } from "../rules/no-instanceof-error/no-instanceof-error.js"
|
|
3
4
|
import { noT } from "../rules/no-t/no-t.js"
|
|
4
5
|
|
|
5
6
|
/** @type {import("@eslint/config-helpers").Config} */
|
|
@@ -9,6 +10,7 @@ export const dvukovic = {
|
|
|
9
10
|
rules: {
|
|
10
11
|
"document-todos": documentTodos,
|
|
11
12
|
"no-commented-out-code": noCommentedOutCode,
|
|
13
|
+
"no-instanceof-error": noInstanceofError,
|
|
12
14
|
"no-t": noT,
|
|
13
15
|
},
|
|
14
16
|
},
|
|
@@ -16,6 +18,7 @@ export const dvukovic = {
|
|
|
16
18
|
rules: {
|
|
17
19
|
"dvukovic/document-todos": ["error", { url: "http" }],
|
|
18
20
|
"dvukovic/no-commented-out-code": "error",
|
|
21
|
+
"dvukovic/no-instanceof-error": "error",
|
|
19
22
|
"dvukovic/no-t": "error",
|
|
20
23
|
},
|
|
21
24
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const noInstanceofError = {
|
|
2
|
+
create(context) {
|
|
3
|
+
return {
|
|
4
|
+
BinaryExpression(node) {
|
|
5
|
+
if (
|
|
6
|
+
node.operator === "instanceof" &&
|
|
7
|
+
node.right.type === "Identifier" &&
|
|
8
|
+
node.right.name === "Error"
|
|
9
|
+
) {
|
|
10
|
+
context.report({
|
|
11
|
+
fix(fixer) {
|
|
12
|
+
const leftText = context.sourceCode.getText(node.left)
|
|
13
|
+
|
|
14
|
+
return fixer.replaceText(node, `Error.isError(${leftText})`)
|
|
15
|
+
},
|
|
16
|
+
messageId: "forbidden",
|
|
17
|
+
node,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
meta: {
|
|
24
|
+
docs: {
|
|
25
|
+
description:
|
|
26
|
+
"Forbids `instanceof Error` in favor of `Error.isError()` which works across realms.",
|
|
27
|
+
},
|
|
28
|
+
fixable: "code",
|
|
29
|
+
messages: {
|
|
30
|
+
forbidden:
|
|
31
|
+
"Use `Error.isError()` instead of `instanceof Error`. It works across realms where `instanceof` fails.",
|
|
32
|
+
},
|
|
33
|
+
schema: [],
|
|
34
|
+
type: "problem",
|
|
35
|
+
},
|
|
36
|
+
}
|