@ornikar/eslint-plugin-ornikar 21.0.0 → 21.2.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,31 @@
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
+ ## [21.2.0](https://github.com/ornikar/eslint-configs/compare/v21.1.0...v21.2.0) (2023-11-02)
7
+
8
+
9
+ ### Features
10
+
11
+ * eslint-plugin-ornikar improve ignoreFiles in typescript-no-unused-exports [no issue] ([#633](https://github.com/ornikar/eslint-configs/issues/633)) ([db2c331](https://github.com/ornikar/eslint-configs/commit/db2c3311de9c53a4f74b30954af273195b9d8f90))
12
+
13
+
14
+
15
+ ## [21.1.0](https://github.com/ornikar/eslint-configs/compare/v21.0.0...v21.1.0) (2023-10-20)
16
+
17
+
18
+ ### Features
19
+
20
+ * **deps:** update typescript-eslint monorepo to v6.8.0 ([#624](https://github.com/ornikar/eslint-configs/issues/624)) ([2b51343](https://github.com/ornikar/eslint-configs/commit/2b51343a953af6cc468f2c16447b4da4d4bc6e9e))
21
+ * **eslint-plugin-ornikar:** add typescript-no-unused-exports rule [no issue] ([#632](https://github.com/ornikar/eslint-configs/issues/632)) ([b5baffe](https://github.com/ornikar/eslint-configs/commit/b5baffef16c3e8e274d5398c303e09ed2d322219))
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * **deps:** update typescript-eslint monorepo to v6.7.4 ([#616](https://github.com/ornikar/eslint-configs/issues/616)) ([c3eb1ce](https://github.com/ornikar/eslint-configs/commit/c3eb1ce5126a26b5fd740e7b1153a6cd015c3bc3))
27
+ * **eslint-plugin-ornikar:** ignore mocks and generated files ([02b6cbf](https://github.com/ornikar/eslint-configs/commit/02b6cbf5c006d25f540895b2304b3a31e1942345))
28
+
29
+
30
+
6
31
  ## [21.0.0](https://github.com/ornikar/eslint-configs/compare/v20.2.1...v21.0.0) (2023-09-26)
7
32
 
8
33
 
package/configs/all.js CHANGED
@@ -4,5 +4,6 @@ module.exports = {
4
4
  rules: {
5
5
  '@ornikar/ornikar/forbid-fetch-import': 'error',
6
6
  '@ornikar/ornikar/react-function-component-return-react-node': 'error',
7
+ '@ornikar/ornikar/typescript-no-unused-exports': 'off', // experimental
7
8
  },
8
9
  };
@@ -3,6 +3,7 @@
3
3
  "jsx": "preserve",
4
4
  "target": "es5",
5
5
  "module": "commonjs",
6
+ "moduleDetection": "force",
6
7
  "strict": true
7
8
  },
8
9
  "include": ["**/*.ts", "**/*.tsx"]
@@ -0,0 +1 @@
1
+ export function UnusedExport(): void {}
@@ -0,0 +1 @@
1
+ export function UsedExport(): void {}
@@ -0,0 +1 @@
1
+ import { UsedExport } from './used-export';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ornikar/eslint-plugin-ornikar",
3
- "version": "21.0.0",
3
+ "version": "21.2.0",
4
4
  "description": "eslint plugin for ornikar",
5
5
  "repository": {
6
6
  "directory": "@ornikar/eslint-plugin-ornikar",
@@ -19,7 +19,13 @@
19
19
  ]
20
20
  },
21
21
  "peerDependencies": {
22
- "eslint": "^8.39.0"
22
+ "eslint": "^8.39.0",
23
+ "typescript": ">=5.2.2"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "typescript": {
27
+ "optional": true
28
+ }
23
29
  },
24
30
  "scripts": {
25
31
  "lint:eslint": "yarn ../.. eslint --report-unused-disable-directives --quiet @ornikar/eslint-plugin-ornikar"
@@ -29,16 +35,17 @@
29
35
  ".": "./index.js"
30
36
  },
31
37
  "dependencies": {
32
- "eslint-plugin-react": "^7.33.2"
38
+ "@typescript-eslint/utils": "6.8.0",
39
+ "eslint-plugin-react": "^7.33.2",
40
+ "ts-unused-exports": "^10.0.1"
33
41
  },
34
42
  "devDependencies": {
35
43
  "@eslint/eslintrc": "2.1.2",
36
- "@typescript-eslint/rule-tester": "6.7.2",
37
- "@typescript-eslint/utils": "6.7.2",
38
- "eslint": "8.49.0"
44
+ "@typescript-eslint/rule-tester": "6.8.0",
45
+ "eslint": "8.52.0",
46
+ "typescript": "5.2.2"
39
47
  },
40
48
  "engines": {
41
49
  "node": ">=18.18.0"
42
- },
43
- "gitHead": "99c0a576f6ee3da108b9101453f6a0954c54b33e"
44
- }
50
+ }
51
+ }
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ const path = require('node:path');
4
+ // eslint-disable-next-line import/no-unresolved -- missing main in package.json
5
+ const { ESLintUtils } = require('@typescript-eslint/utils');
6
+ const { default: analyzeTsConfig } = require('ts-unused-exports');
7
+
8
+ exports.meta = {
9
+ type: 'problem',
10
+
11
+ docs: {
12
+ description: 'Identifies unused exports using "ts-unused-exports". Made for usage with vscode only.',
13
+ category: 'Best Practices',
14
+ recommended: false, // experimental
15
+ },
16
+
17
+ messages: {
18
+ unusedExport: "Export '{{exportName}}' is unused.",
19
+ removeExport: "Remove export '{{exportName}}'.",
20
+ },
21
+
22
+ hasSuggestions: true,
23
+
24
+ schema: [
25
+ {
26
+ additionalProperties: false,
27
+ properties: {
28
+ allowUnusedEnums: {
29
+ type: 'boolean',
30
+ },
31
+ allowUnusedTypes: {
32
+ type: 'boolean',
33
+ },
34
+ ignoreFiles: {
35
+ type: 'string',
36
+ },
37
+ },
38
+ type: 'object',
39
+ },
40
+ ],
41
+ };
42
+
43
+ function getSuggestionFixer(node) {
44
+ return (fixer) => {
45
+ return fixer.remove(node);
46
+ };
47
+ }
48
+
49
+ exports.create = (context) => {
50
+ const options = context.options || {};
51
+
52
+ const services = ESLintUtils.getParserServices(context);
53
+ // configFilePath is all lowercase on mac
54
+ const tsconfigPathLowercased = services.program.getCompilerOptions().configFilePath;
55
+ // should cover ornikar case.
56
+ const tsconfigPath = path.join(process.cwd(), path.relative(process.cwd().toLowerCase(), tsconfigPathLowercased));
57
+
58
+ const tsUnusedOptions = [
59
+ '--ignoreFiles=/(__mocks__|__generated__)/',
60
+ '--ignoreFiles=[.](web|ios|android)$',
61
+ '--ignoreFiles=apollo/typeDefs$',
62
+ ];
63
+
64
+ if (options.allowUnusedEnums) {
65
+ tsUnusedOptions.push('--allowUnusedEnums');
66
+ }
67
+
68
+ if (options.allowUnusedTypes) {
69
+ tsUnusedOptions.push('--allowUnusedTypes');
70
+ }
71
+
72
+ if (options.ignoreFiles) {
73
+ tsUnusedOptions.push(`--ignoreFiles=${options.ignoreFiles}`);
74
+ }
75
+
76
+ const result = analyzeTsConfig(tsconfigPath, tsUnusedOptions);
77
+
78
+ return {
79
+ Program() {
80
+ const filename = context.getFilename();
81
+
82
+ if (!result[filename]) {
83
+ return;
84
+ }
85
+
86
+ const sourceCode = context.getSourceCode();
87
+
88
+ for (const unusedExport of result[filename]) {
89
+ const index = sourceCode.getIndexFromLoc({
90
+ column: unusedExport.location.character,
91
+ line: unusedExport.location.line,
92
+ });
93
+
94
+ const exportToken = sourceCode.getTokenByRangeStart(index);
95
+
96
+ if (!exportToken) {
97
+ throw new Error('Expected export node');
98
+ }
99
+
100
+ context.report({
101
+ node: exportToken,
102
+ messageId: 'unusedExport',
103
+ data: { exportName: unusedExport.exportName },
104
+ suggest: [
105
+ {
106
+ messageId: 'removeExport',
107
+ data: { exportName: unusedExport.exportName },
108
+ fix: getSuggestionFixer(exportToken),
109
+ },
110
+ ],
111
+ });
112
+ }
113
+ },
114
+ };
115
+ };
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { RuleTester } = require('./test-utils/RuleTester');
6
+ const rule = require('./typescript-no-unused-exports');
7
+
8
+ const ruleTester = new RuleTester({
9
+ parser: require.resolve('@typescript-eslint/parser'),
10
+ parserOptions: {
11
+ tsconfigRootDir: path.join(__dirname, '../fixtures'),
12
+ project: './tsconfig.json',
13
+ },
14
+ });
15
+
16
+ const fixturesPath = path.join(__dirname, '../fixtures');
17
+
18
+ ruleTester.run('typescript-no-unused-exports', rule, {
19
+ valid: [
20
+ {
21
+ filename: path.join(fixturesPath, 'used-export.ts'),
22
+ code: fs.readFileSync(path.join(fixturesPath, 'used-export.ts'), 'utf8'),
23
+ },
24
+ ],
25
+ invalid: [
26
+ {
27
+ filename: path.join(fixturesPath, 'unused-export.ts'),
28
+ code: fs.readFileSync(path.join(fixturesPath, 'unused-export.ts'), 'utf8'),
29
+ errors: [
30
+ {
31
+ messageId: 'unusedExport',
32
+ data: { exportName: 'UnusedExport' },
33
+ line: 1,
34
+ endLine: 1,
35
+ column: 1,
36
+ endColumn: 7,
37
+ suggestions: [
38
+ {
39
+ messageId: 'removeExport',
40
+ data: { exportName: 'UnusedExport' },
41
+ output: ` function UnusedExport(): void {}
42
+ `,
43
+ },
44
+ ],
45
+ },
46
+ ],
47
+ },
48
+ ],
49
+ });