Skip to content

Commit 997165e

Browse files
committed
INCOMPLETE
1. Add tests (for desired features added to docs) -> implement 2. (apparent problem in eslint itself with our use of Program:exit): test(`no-undefined-types`): issues gajus#507
1 parent 4f73e9c commit 997165e

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

.README/rules/no-undefined-types.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,38 @@ reporting on use of that namepath elsewhere) and/or that a tag's `type` is
4343

4444
#### Options
4545

46-
An option object may have the following key:
46+
An option object may have the following keys, helping indicate types or
47+
file sources of types:
4748

4849
- `definedTypes` - This array can be populated to indicate other types which
4950
are automatically considered as defined (in addition to globals, etc.).
5051
Defaults to an empty array.
5152

53+
- `entryFiles` - Array of entry files objects indicating JavaScript or HTML
54+
files whose `import` or `require` statements should be resolved recursively
55+
and be analyzed for `@typedef`'s or globals to treat as "defined" for the
56+
purposes of this rule. Each object should have a `file` array and with an
57+
optional `node` property to indicate whether to use the Node Resolution
58+
Algorithm (e.g., for Node.js) and/or `cjs` (if following `require`)
59+
properties. Set one of the `file` items to `<main>`, `<exports>`,
60+
`<exports.imports>`, or `<exports.require>` to use the file referenced in
61+
the correpsonding property in `package.json`.
62+
63+
- `jsdocConfig` - Object with:
64+
1. `file` string pointing to a path for a
65+
[jsdoc config file](https://jsdoc.app/about-configuring-jsdoc.html)
66+
which will be parsed for [input files](https://jsdoc.app/about-configuring-jsdoc.html#specifying-input-files),
67+
including `include`, `exclude`, `includePattern`, and `excludePattern`
68+
properties within the file as well as `opts.recurse`. See `entryFiles`
69+
on how the (JavaScript) files will be treated (with
70+
`sourceType: 'module'` in the jsdoc config file causing "cjs" to be
71+
set to `false`).
72+
73+
- `typeSources` - Array with `globals`, `exports`, and/or `locals` indicating
74+
the source types that will be treated as valid types when found in the
75+
current file or any entry files (`locals` will only apply to the
76+
current file).
77+
5278
|||
5379
|---|---|
5480
|Context|everywhere|

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6536,12 +6536,38 @@ reporting on use of that namepath elsewhere) and/or that a tag's `type` is
65366536
<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-15"></a>
65376537
#### Options
65386538
6539-
An option object may have the following key:
6539+
An option object may have the following keys, helping indicate types or
6540+
file sources of types:
65406541
65416542
- `definedTypes` - This array can be populated to indicate other types which
65426543
are automatically considered as defined (in addition to globals, etc.).
65436544
Defaults to an empty array.
65446545
6546+
- `entryFiles` - Array of entry files objects indicating JavaScript or HTML
6547+
files whose `import` or `require` statements should be resolved recursively
6548+
and be analyzed for `@typedef`'s or globals to treat as "defined" for the
6549+
purposes of this rule. Each object should have a `file` array and with an
6550+
optional `node` property to indicate whether to use the Node Resolution
6551+
Algorithm (e.g., for Node.js) and/or `cjs` (if following `require`)
6552+
properties. Set one of the `file` items to `<main>`, `<exports>`,
6553+
`<exports.imports>`, or `<exports.require>` to use the file referenced in
6554+
the correpsonding property in `package.json`.
6555+
6556+
- `jsdocConfig` - Object with:
6557+
1. `file` string pointing to a path for a
6558+
[jsdoc config file](https://jsdoc.app/about-configuring-jsdoc.html)
6559+
which will be parsed for [input files](https://jsdoc.app/about-configuring-jsdoc.html#specifying-input-files),
6560+
including `include`, `exclude`, `includePattern`, and `excludePattern`
6561+
properties within the file as well as `opts.recurse`. See `entryFiles`
6562+
on how the (JavaScript) files will be treated (with
6563+
`sourceType: 'module'` in the jsdoc config file causing "cjs" to be
6564+
set to `false`).
6565+
6566+
- `typeSources` - Array with `globals`, `exports`, and/or `locals` indicating
6567+
the source types that will be treated as valid types when found in the
6568+
current file or any entry files (`locals` will only apply to the
6569+
current file).
6570+
65456571
|||
65466572
|---|---|
65476573
|Context|everywhere|
@@ -7033,6 +7059,30 @@ function quux () {}
70337059
* @type {SomeType}
70347060
*/
70357061
// Settings: {"jsdoc":{"structuredTags":{"namepathDefiner":{"name":"namepath-defining"}}}}
7062+
7063+
import {myTypesA} from '../internal/file.js'; // ERROR
7064+
import {myTypesB} from '../internal/file.js'; // NO ERROR
7065+
7066+
/**
7067+
* @typedef newType
7068+
* @property {myTypesA.someType} someProp - Some prop.
7069+
*/
7070+
7071+
/**
7072+
* @param {newType} arg - Arg.
7073+
*/
7074+
function myFunctionA(arg) {
7075+
return arg;
7076+
}
7077+
7078+
/**
7079+
* @param {myTypesB.someType} arg - Arg.
7080+
*/
7081+
function myFunctionB(arg) {
7082+
return arg;
7083+
}
7084+
7085+
export {myFunctionA, myFunctionB};
70367086
````
70377087
70387088

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dependencies": {
88
"comment-parser": "^0.7.6",
99
"debug": "^4.1.1",
10+
"es-file-traverse": "^0.1.2",
1011
"jsdoctypeparser": "^9.0.0",
1112
"lodash": "^4.17.20",
1213
"regextras": "^0.7.1",

test/rules/assertions/noUndefinedTypes.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,5 +897,38 @@ export default {
897897
},
898898
},
899899
},
900+
{
901+
code: `
902+
import {myTypesA} from '../internal/file.js'; // ERROR
903+
import {myTypesB} from '../internal/file.js'; // NO ERROR
904+
905+
/**
906+
* @typedef newType
907+
* @property {myTypesA.someType} someProp - Some prop.
908+
*/
909+
910+
/**
911+
* @param {newType} arg - Arg.
912+
*/
913+
function myFunctionA(arg) {
914+
return arg;
915+
}
916+
917+
/**
918+
* @param {myTypesB.someType} arg - Arg.
919+
*/
920+
function myFunctionB(arg) {
921+
return arg;
922+
}
923+
924+
export {myFunctionA, myFunctionB};
925+
`,
926+
parserOptions: {
927+
sourceType: 'module',
928+
},
929+
rules: {
930+
'no-unused-vars': ['error'],
931+
},
932+
},
900933
],
901934
};

0 commit comments

Comments
 (0)