Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce scope of --ignoreTestFiles. Alter return type so file dict is under 'unusedExports'. Include #311 Fix the default export error for esm module. #313

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lib": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"typescript.tsdk": "node_modules/typescript/lib"
}
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## [11.0.0] - 25 Nov 2024

### Changed

- BREAKING CHANGE: The default export (API entry point) has been changed to be compatible with esm module (should also work with cjs)
- BREAKING CHANGE: The results (API) structure has been changed:
- OLD:
```ts
const result = {
"filePath1": { /* ... */ },
"filePath2": { /* ... */ },
/* ... */
unusedFiles: { /* ... */ },
};
```
- NEW:
```ts
const result = {
unusedExports: {
"filePath1": { /* ... */ },
"filePath2": { /* ... */ },
/* ... */
},
unusedFiles: [ "filePath1", "filePath2", /*"..."*/ ]
};
```
- fix: The scope of --ignoreTestFiles has been reduced, to make it less likely to exclude non-test files
- (internal) built using Node v20.13.1

## [10.1.0] - 24 May 2024

### Changed
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ If you don't know where to put the breakpoint, you can always put it in the firs

Hint: to simplify debugging, you can comment out all the other tests in the file.
In **Visual Code**, a quick way to do this, is to select the tests you want to skip, and press `CTRL + /`.

Hint: to run only certain tests from the command line, place the `@only` decorator just before the test. Then execute them via `test:unit:only`.
14 changes: 7 additions & 7 deletions features/base-url-undefined.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ Scenario: Import named with base url
Given file "a.ts" is export const a = 1;
And file "b.ts" is import { a } from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Import named with base url TSX
Given file "a.tsx" is export const a = 1;
And file "b.ts" is import { a } from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Import default with base url
Given file "a.ts" is export default 1;
And file "b.ts" is import a from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Import default with base url TSX
Given file "a.tsx" is export default 1;
And file "b.ts" is import a from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Index TS
Given file "dir/index.ts" is export default 1;
And file "b.ts" is import a from 'dir';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Index JS
Given file "dir/index.js" is export default 1;
And file "b.ts" is import a from 'dir';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Index TSX
Given file "dir/index.tsx" is export default 1;
And file "b.ts" is import a from 'dir';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }
14 changes: 7 additions & 7 deletions features/base-url.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@ Scenario: Import named with base url
Given file "stuff/a.ts" is export const a = 1;
And file "b.ts" is import { a } from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Import named with base url TSX
Given file "stuff/a.tsx" is export const a = 1;
And file "b.ts" is import { a } from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Import default with base url
Given file "stuff/a.ts" is export default 1;
And file "b.ts" is import a from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Import default with base url TSX
Given file "stuff/a.tsx" is export default 1;
And file "b.ts" is import a from 'a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Index TS
Given file "stuff/dir/index.ts" is export default 1;
And file "b.ts" is import a from 'dir';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Index JS
Given file "stuff/dir/index.js" is export default 1;
And file "b.ts" is import a from 'dir';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Index TSX
Given file "stuff/dir/index.tsx" is export default 1;
And file "b.ts" is import a from 'dir';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }
8 changes: 4 additions & 4 deletions features/exclude-paths-from-report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ Feature: ignore paths
Scenario: Ignore all
Given file "exports.ts" is export const a = 1;
When analyzing "tsconfig.json" with files ["--excludePathsFromReport=exports;other-1"]
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Ignore all using regex
Given file "test/a.ts" is export const a = 1;
And file "test/b.ts" is export const b = 1;
And file "test/c.ts" is export const c = 1;
When analyzing "tsconfig.json" with files ["--excludePathsFromReport=test\/(a|b)"]
Then the result is { "test/c.ts": ["c"] }
Then the result is { "unusedExports": { "test/c.ts": ["c"] } }

Scenario: Ignore none
Given file "exports.ts" is export const a = 1;
When analyzing "tsconfig.json" with files ["--excludePathsFromReport=other-1;other-2"]
Then the result is { "exports.ts": ["a"] }
Then the result is { "unusedExports": {"exports.ts": ["a"] } }

Scenario: Extra semi-colons doesn't filter all results
Given file "exports.ts" is export const a = 1;
When analyzing "tsconfig.json" with files ["--excludePathsFromReport=other-1;;other-2;"]
Then the result is { "exports.ts": ["a"] }
Then the result is { "unusedExports": {"exports.ts": ["a"] } }
4 changes: 2 additions & 2 deletions features/export-array.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Scenario: export simple array
import { x, y, z } from './a';
"""
When analyzing "tsconfig.json"
Then the result is { "a.ts": ["unused"] }
Then the result is { "unusedExports": { "a.ts": ["unused"] } }

Scenario: export simple array, with alias
Given file "a.ts" is
Expand All @@ -22,4 +22,4 @@ Scenario: export simple array, with alias
import { x as x1, y, z } from './a';
"""
When analyzing "tsconfig.json"
Then the result is { "a.ts": ["unused"] }
Then the result is { "unusedExports": { "a.ts": ["unused"] } }
30 changes: 15 additions & 15 deletions features/export-statements-star.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Scenario: export * from ./a/a.ts
And file "c.ts" is import { A } from './b';

When analyzing "tsconfig.json"
Then the result is { "b.ts": ["A_unused"] }
Then the result is { "unusedExports": { "b.ts": ["A_unused"] } }

Scenario: export * from ./a/a/a.ts
Given file "a/a/a.ts" is
Expand All @@ -32,7 +32,7 @@ Scenario: export * from ./a/a/a.ts

When analyzing "tsconfig.json"
# note A_innermost_unused is not detected - that would require parsing for all usages of the namespace
Then the result is { "a/index.ts": ["A_unused"] }
Then the result is { "unusedExports": { "a/index.ts": ["A_unused"] } }

Scenario: export * from ./a1/a2/a.ts
Given file "a1/a2/a.ts" is
Expand All @@ -54,7 +54,7 @@ Scenario: export * from ./a1/a2/a.ts

When analyzing "tsconfig.json"
# note A_innermost_unused is not detected - that would require parsing for all usages of the namespace
Then the result is { "a1/index.ts": ["A_unused"] }
Then the result is { "unusedExports": { "a1/index.ts": ["A_unused"] } }

Scenario: export * from ./a1/a2/a.ts - import skipping the mid-level - import from innermost index
Given file "a1/a2/a.ts" is
Expand All @@ -78,7 +78,7 @@ Scenario: export * from ./a1/a2/a.ts - import skipping the mid-level - import fr

When analyzing "tsconfig.json"
# note A_innermost_unused is NOT detected
Then the result is { "a1/a_ts":["* -> /a1/a2/a"], "a1/index.ts": ["A_unused"] }
Then the result is { "unusedExports": { "a1/a_ts":["* -> /a1/a2/a"], "a1/index.ts": ["A_unused"] } }

Scenario: export * from ./a1/a2/a.ts - import skipping the mid-level - import from innermost a.ts
Given file "a1/a2/a.ts" is
Expand All @@ -104,7 +104,7 @@ Scenario: export * from ./a1/a2/a.ts - import skipping the mid-level - import fr
When analyzing "tsconfig.json"
# note A_innermost_unused is NOT detected
# TODO review - A is flagged via "a1/a2/index_ts":["A"...] - which is strictly correct, although could be annoying
Then the result is { "a1/index.ts": ["A_unused"],"a1/a2/index_ts":["A","A_innermost_unused"] }
Then the result is { "unusedExports": { "a1/index.ts": ["A_unused"],"a1/a2/index_ts":["A","A_innermost_unused"] } }

Scenario: export * from ./a/a/a.ts - import skipping the mid-level
Given file "a/a/a.ts" is
Expand All @@ -128,7 +128,7 @@ Scenario: export * from ./a/a/a.ts - import skipping the mid-level

When analyzing "tsconfig.json"
# note A_innermost_unused IS detected
Then the result is { "a/index.ts": ["A_unused", "A_innermost_unused"] }
Then the result is { "unusedExports": { "a/index.ts": ["A_unused", "A_innermost_unused"] } }

Scenario: export * from ./a/a/a.ts - import skipping the mid-level
Given file "a/a/a.ts" is
Expand All @@ -152,7 +152,7 @@ Scenario: export * from ./a/a/a.ts - import skipping the mid-level

When analyzing "tsconfig.json"
# note A_innermost_unused is NOT detected
Then the result is { "a/index.ts": ["A_unused"] }
Then the result is { "unusedExports": { "a/index.ts": ["A_unused"] } }

Scenario: export * from ./a
Given file "a/index.ts" is
Expand All @@ -164,7 +164,7 @@ Scenario: export * from ./a
And file "c.ts" is import { A } from './b';

When analyzing "tsconfig.json"
Then the result is { "b.ts": ["A_unused"] }
Then the result is { "unusedExports": { "b.ts": ["A_unused"] } }

Scenario: export * as fromA from ./a/a.ts
Given file "a/a.ts" is
Expand All @@ -177,7 +177,7 @@ Scenario: export * as fromA from ./a/a.ts

When analyzing "tsconfig.json"
# note A_unused is not detected - that would require parsing for all usages of the namespace
Then the result is { }
Then the result is { "unusedExports": {} }

Scenario: export * as fromA from ./a/a.ts
Given file "a/a.ts" is
Expand All @@ -189,7 +189,7 @@ Scenario: export * as fromA from ./a/a.ts
And file "c.ts" is import { fromA } from './b';

When analyzing "tsconfig.json"
Then the result is { }
Then the result is { "unusedExports": { } }
# note A_unused is not detected - that would require parsing for all usages of the namespace

Scenario: export * as fromA from ./src/a.ts
Expand All @@ -202,7 +202,7 @@ Scenario: export * as fromA from ./src/a.ts
And file "src/c.ts" is import { fromA } from './b';

When analyzing "tsconfig.json"
Then the result is { }
Then the result is { "unusedExports": {} }
# note A_unused is not detected - that would require parsing for all usages of the namespace

Scenario: export * as fromA from ./src/a.ts
Expand All @@ -215,7 +215,7 @@ Scenario: export * as fromA from ./src/a.ts
And file "src/c.ts" is import { fromA } from './b';

When analyzing "tsconfig.json"
Then the result is { }
Then the result is { "unusedExports": {} }
# note A_unused is not detected - that would require parsing for all usages of the namespace

Scenario: export * as fromA from ./src/a.ts
Expand All @@ -228,7 +228,7 @@ Scenario: export * as fromA from ./src/a.ts
And file "c.ts" is import * as fromA2 from 'src/b';

When analyzing "tsconfig.json"
Then the result is { }
Then the result is { "unusedExports": {} }
# note A_unused is not detected - that would require parsing for all usages of the namespace

Scenario: export * as fromA from ./a.ts
Expand All @@ -241,7 +241,7 @@ Scenario: export * as fromA from ./a.ts
And file "c.ts" is import * as fromA2 from './b';

When analyzing "tsconfig.json"
Then the result is { }
Then the result is { "unusedExports": {} }

Scenario: export * as fromA from ./a
Given file "a/index.ts" is
Expand All @@ -253,5 +253,5 @@ Scenario: export * as fromA from ./a
And file "c.ts" is import { fromA } from './b';

When analyzing "tsconfig.json"
Then the result is { }
Then the result is { "unusedExports": {} }
# note A_unused is not detected - that would require parsing for all usages of the namespace
14 changes: 7 additions & 7 deletions features/export-statements.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Scenario: export { a }
"""
And file "b.ts" is import { a } from './a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: export { a } from file
Given file "a.ts" is export const a = 1;
Expand All @@ -19,7 +19,7 @@ Scenario: export { a } from file
"""
And file "c.ts" is import { a } from './b';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }

Scenario: Include files from sub-folder, without error
Given file "x/a.ts" is
Expand All @@ -33,7 +33,7 @@ Scenario: Include files from sub-folder, without error
export const a: A = 0
"""
When analyzing "tsconfig.json"
Then the result is { "b.ts": ["a"], "x/a.ts": ["A_unused"] }
Then the result is { "unusedExports": { "b.ts": ["a"], "x/a.ts": ["A_unused"] } }

Scenario: Include re-exported types from sub-folder, without error
Given file "x/a.ts" is
Expand All @@ -53,7 +53,7 @@ Scenario: Include re-exported types from sub-folder, without error
export type C_unused = 2;
"""
When analyzing "tsconfig.json"
Then the result is { "b.ts": ["B_unused"], "c.ts": ["C_unused"], "x/a.ts": ["A_unused"] }
Then the result is { "unusedExports": { "b.ts": ["B_unused"], "c.ts": ["C_unused"], "x/a.ts": ["A_unused"] } }

Scenario: Include files indirectly from sub-folder, without error
Given file "x/a.ts" is
Expand All @@ -75,7 +75,7 @@ Scenario: Include files indirectly from sub-folder, without error
export type C_unused = 2;
"""
When analyzing "tsconfig.json"
Then the result is { "b.ts": ["B_unused"], "c.ts": ["C_unused"], "x/a.ts": ["A_unused"] }
Then the result is { "unusedExports": { "b.ts": ["B_unused"], "c.ts": ["C_unused"], "x/a.ts": ["A_unused"] } }

Scenario: Import a destructured export
Given file "a.ts" is
Expand All @@ -90,7 +90,7 @@ Scenario: Import a destructured export
export const B_unused = 1;
"""
When analyzing "tsconfig.json"
Then the result is { "b.ts": ["B_unused"], "a.ts": ["A_unused"] }
Then the result is { "unusedExports": { "b.ts": ["B_unused"], "a.ts": ["A_unused"] } }

Scenario: Import a destructured export with renamings
Given file "a.ts" is
Expand All @@ -105,4 +105,4 @@ Scenario: Import a destructured export with renamings
export const B_unused = 1;
"""
When analyzing "tsconfig.json"
Then the result is { "b.ts": ["B_unused"], "a.ts": ["A_unused"] }
Then the result is { "unusedExports": { "b.ts": ["B_unused"], "a.ts": ["A_unused"] } }
2 changes: 1 addition & 1 deletion features/exported-default-as.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Scenario: Export default as
Given file "b.ts" is export { default as foo } from './a';
And file "c.ts" is import {foo} from "./b"
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }
2 changes: 1 addition & 1 deletion features/exported-default-function.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Scenario: Missing default
Scenario: Import default
Given file "b.ts" is import def from './a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }
2 changes: 1 addition & 1 deletion features/exported-default-named-function.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Scenario: Missing default
Scenario: Import default
Given file "b.ts" is import def from './a';
When analyzing "tsconfig.json"
Then the result is {}
Then the result is { "unusedExports": {} }
Loading
Loading