@pob/eslint-plugin 59.6.0 → 59.8.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/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [59.8.0](https://github.com/christophehurpeau/eslint-config-pob/compare/v59.7.0...v59.8.0) (2025-03-09)
7
+
8
+ ### Features
9
+
10
+ * add colorette ([82adbbf](https://github.com/christophehurpeau/eslint-config-pob/commit/82adbbf5081a38301ef962b3f0073e1e2565d8ee))
11
+ * update typescript ([090972e](https://github.com/christophehurpeau/eslint-config-pob/commit/090972ef3c80511454a8608890d33133dbc3570a))
12
+
13
+ ## [59.7.0](https://github.com/christophehurpeau/eslint-config-pob/compare/v59.6.0...v59.7.0) (2025-02-17)
14
+
15
+ ### Features
16
+
17
+ * add rule forbid-non-native-node-imports ([0fde6ee](https://github.com/christophehurpeau/eslint-config-pob/commit/0fde6ee308683df6f3804616a216bb7d70969700))
18
+ * update eslint-plugin-unicorn ([c8c18f2](https://github.com/christophehurpeau/eslint-config-pob/commit/c8c18f25dde42b9b69d0178d876c4eebe4cce017))
19
+
6
20
  ## [59.6.0](https://github.com/christophehurpeau/eslint-config-pob/compare/v59.5.1...v59.6.0) (2025-02-06)
7
21
 
8
22
  ### Features
@@ -0,0 +1,6 @@
1
+ export default {
2
+ name: "@pob/eslint-plugin/configs/node",
3
+ rules: {
4
+ "@pob/forbid-non-native-node-imports": "error",
5
+ },
6
+ };
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import baseConfig from "./configs/base.js";
2
+ import nodeConfig from "./configs/node.js";
2
3
  import reactConfig from "./configs/react.js";
3
4
  import { loadRules } from "./loadRules.js";
4
5
 
@@ -9,5 +10,6 @@ export default {
9
10
  configs: {
10
11
  base: baseConfig,
11
12
  react: reactConfig,
13
+ node: nodeConfig,
12
14
  },
13
15
  };
package/lib/loadRules.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import forbidNonNativeFetchImportRule from "./rules/forbid-non-native-fetch-import.js";
4
+ import forbidNonNativeNodeImportsRule from "./rules/forbid-non-native-node-imports.js";
4
5
  import reactFunctionComponentReturnReactNodeRule from "./rules/react-function-component-return-react-node.js";
5
6
  import reactNamedImportRule from "./rules/react-named-import.js";
6
7
 
@@ -37,6 +38,10 @@ export function loadRules() {
37
38
  "forbid-non-native-fetch-import",
38
39
  forbidNonNativeFetchImportRule,
39
40
  ),
41
+ "forbid-non-native-node-imports": loadRule(
42
+ "forbid-non-native-node-imports",
43
+ forbidNonNativeNodeImportsRule,
44
+ ),
40
45
  "react-function-component-return-react-node": loadRule(
41
46
  "react-function-component-return-react-node",
42
47
  reactFunctionComponentReturnReactNodeRule,
@@ -0,0 +1,50 @@
1
+ const libsToNativeNode = [
2
+ {
3
+ libs: ["chalk", "colorette"],
4
+ replaceWith: "styleText from node:util",
5
+ },
6
+ ];
7
+
8
+ export default {
9
+ meta: {
10
+ type: "problem",
11
+
12
+ docs: {
13
+ description:
14
+ "Forbid node-native import now that node solution is available in natively",
15
+ category: "Best Practices",
16
+ recommended: true,
17
+ },
18
+
19
+ messages: {
20
+ forbidden:
21
+ 'import from "{{value}}" is forbidden. Replace with "{{nativeImport}}"',
22
+ },
23
+ },
24
+
25
+ create: (context) => {
26
+ const checkNode = (node) => {
27
+ const importSource = node.source.value.trim();
28
+
29
+ const lib = libsToNativeNode.find((lib) =>
30
+ lib.libs.includes(importSource),
31
+ );
32
+ if (lib) {
33
+ context.report({
34
+ node,
35
+ messageId: "forbidden",
36
+ data: { value: importSource, nativeImport: lib.replaceWith },
37
+ });
38
+ }
39
+ };
40
+ return {
41
+ ImportDeclaration: checkNode,
42
+ ExportNamedDeclaration(node) {
43
+ if (node.source) {
44
+ checkNode(node);
45
+ }
46
+ },
47
+ ExportAllDeclaration: checkNode,
48
+ };
49
+ },
50
+ };
@@ -0,0 +1,34 @@
1
+ import { RuleTester } from "eslint";
2
+ import rule from "./forbid-non-native-node-imports.js";
3
+
4
+ const ruleTester = new RuleTester({
5
+ languageOptions: {
6
+ ecmaVersion: 2018,
7
+ sourceType: "module",
8
+ },
9
+ });
10
+
11
+ // @ts-ignore
12
+ ruleTester.run("forbid-non-native-node-imports", rule, {
13
+ valid: [
14
+ {
15
+ code: `
16
+ import { styleText } from 'node:util';
17
+ `,
18
+ },
19
+ ],
20
+ invalid: [
21
+ {
22
+ code: `
23
+ import chalk from 'chalk';
24
+ chalk.red('Hello, world!');
25
+ `,
26
+ errors: [
27
+ {
28
+ messageId: "forbidden",
29
+ data: { value: "chalk", nativeImport: "styleText from node:util" },
30
+ },
31
+ ],
32
+ },
33
+ ],
34
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pob/eslint-plugin",
3
- "version": "59.6.0",
3
+ "version": "59.8.0",
4
4
  "description": "eslint plugin for react",
5
5
  "keywords": [],
6
6
  "author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
@@ -35,7 +35,7 @@
35
35
  "prettier": "@pob/root/prettier-config",
36
36
  "peerDependencies": {
37
37
  "eslint": "^9.9.0",
38
- "typescript": ">=5.0.0 <5.8.0"
38
+ "typescript": ">=5.0.0 <6.0.0"
39
39
  },
40
40
  "peerDependenciesMeta": {
41
41
  "typescript": {
@@ -43,14 +43,13 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@typescript-eslint/utils": "8.23.0",
46
+ "@typescript-eslint/utils": "8.26.0",
47
47
  "eslint-plugin-react": "^7.35.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@eslint/eslintrc": "3.2.0",
51
- "@typescript-eslint/rule-tester": "8.23.0",
52
- "eslint": "9.19.0",
53
- "typescript": "5.7.3",
54
- "typescript-eslint": "8.23.0"
50
+ "@typescript-eslint/rule-tester": "8.26.0",
51
+ "eslint": "9.20.1",
52
+ "typescript": "5.8.2",
53
+ "typescript-eslint": "8.26.0"
55
54
  }
56
55
  }