@dvukovic/style-guide 0.16.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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvukovic/style-guide",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "My own style guide",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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")
@@ -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) {
@@ -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
+ }