Skip to content

Commit 97329b6

Browse files
committed
chore: add eslint-plugin-jsdoc
1 parent 58c644f commit 97329b6

19 files changed

+121
-47
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ module.exports = {
77
'plugin:eslint-plugin/recommended',
88
'plugin:node/recommended',
99
'prettier',
10+
'plugin:jsdoc/recommended',
1011
],
11-
plugins: ['prettier'],
12+
plugins: ['prettier', 'jsdoc'],
1213
rules: {
1314
'prettier/prettier': 'error',
1415
},

lib/constants/naming-convention.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview Built in filename naming convention
2+
* @file Built in filename naming convention
33
* @author Duke Luo
44
*/
55
'use strict';

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview check the file folder
2+
* @file check the file folder
33
* @author Duke Luo
44
*/
55
'use strict';

lib/rules/filename-blacklist.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview The filename should not be blacklisted.
2+
* @file The filename should not be blacklisted.
33
* @author Florian Ehmke
44
*/
55
'use strict';
@@ -9,8 +9,9 @@ const { checkSettings, globPatternValidator } = require('../utils/settings');
99
const { getDocUrl } = require('../utils/doc');
1010
const { matchRule } = require('../utils/match');
1111

12+
/** @typedef {module:eslint} ESLint */
1213
/**
13-
* @type {import('eslint').Rule.RuleModule}
14+
* @type {ESLint.Rule.RuleModule}
1415
*/
1516
module.exports = {
1617
meta: {

lib/rules/filename-naming-convention.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview The filename should follow the filename naming convention
2+
* @file The filename should follow the filename naming convention
33
* @author Duke Luo
44
*/
55
'use strict';
@@ -13,8 +13,9 @@ const {
1313
const { getDocUrl } = require('../utils/doc');
1414
const { matchRule } = require('../utils/match');
1515

16+
/** @typedef {module:eslint} ESLint */
1617
/**
17-
* @type {import('eslint').Rule.RuleModule}
18+
* @type {ESLint.Rule.RuleModule}
1819
*/
1920
module.exports = {
2021
meta: {

lib/rules/folder-match-with-fex.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview The folder should match the naming pattern specified by the file extension
2+
* @file The folder should match the naming pattern specified by the file extension
33
* @author Duke Luo
44
*/
55
'use strict';
@@ -13,8 +13,9 @@ const { checkSettings, globPatternValidator } = require('../utils/settings');
1313
const { getDocUrl } = require('../utils/doc');
1414
const { matchRule } = require('../utils/match');
1515

16+
/** @typedef {module:eslint} ESLint */
1617
/**
17-
* @type {import('eslint').Rule.RuleModule}
18+
* @type {ESLint.Rule.RuleModule}
1819
*/
1920
module.exports = {
2021
meta: {

lib/rules/folder-naming-convention.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview The folder should follow the folder naming convention
2+
* @file The folder should follow the folder naming convention
33
* @author Duke Luo
44
*/
55
'use strict';
@@ -19,8 +19,9 @@ const {
1919
const { getDocUrl } = require('../utils/doc');
2020
const NAMING_CONVENTION = require('../constants/naming-convention');
2121

22+
/** @typedef {module:eslint} ESLint */
2223
/**
23-
* @type {import('eslint').Rule.RuleModule}
24+
* @type {ESLint.Rule.RuleModule}
2425
*/
2526
module.exports = {
2627
meta: {

lib/rules/no-index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
2-
* @fileoverview A file cannot be named "index"
2+
* @file A file cannot be named "index"
33
* @author Duke Luo
44
*/
55
'use strict';
66

77
const { getDocUrl } = require('../utils/doc');
88
const { getFilename, getBasename, getFilePath } = require('../utils/filename');
99

10+
/** @typedef {module:eslint} ESLint */
1011
/**
11-
* @type {import('eslint').Rule.RuleModule}
12+
* @type {ESLint.Rule.RuleModule}
1213
*/
1314
module.exports = {
1415
meta: {

lib/utils/doc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
2-
* @fileoverview Utils about document
2+
* @file Utils about document
33
* @author Duke Luo
44
*/
55
'use strict';
66

77
/**
8-
* @type {string} rule document url
8+
* @returns {string} rule document url
99
* @param {string} rule rule name
1010
*/
1111
const getDocUrl = (rule) =>

lib/utils/filename.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
/**
2-
* @fileoverview Utils about filename
2+
* @file Utils about filename
33
* @author Duke Luo
44
*/
55
'use strict';
66

77
const path = require('path');
88

99
/**
10-
* @type {string} filename without path
10+
* @returns {string} filename without path
1111
* @param {string} p filename concat with path in posix style
1212
*/
1313
const getFilename = (p) => path.posix.basename(p);
1414

1515
/**
16-
* @type {string} path of folder
16+
* @returns {string} path of folder
1717
* @param {string} p filename concat with path in posix style
1818
*/
1919
const getFolderPath = (p) =>
2020
path.posix.join(path.posix.dirname(p), path.posix.sep);
2121

2222
/**
23-
* @type {string} base name
23+
* @returns {string} base name
2424
* @param {string} filename filename without path
2525
* @param {boolean} [ignoreMiddleExtensions=false] flag to ignore middle extensions
2626
*/
@@ -31,14 +31,14 @@ const getBasename = (filename, ignoreMiddleExtensions = false) =>
3131
);
3232

3333
/**
34-
* @type {string[]} all folders
34+
* @returns {string[]} all folders
3535
* @param {string} p path of folder in posix style
3636
*/
3737
const getAllFolders = (p) =>
3838
p.split(path.posix.sep).filter((folder) => folder !== '');
3939

4040
/**
41-
* @type {string[]} all sub paths
41+
* @returns {string[]} all sub paths
4242
* @param {string} p path of folder in posix style
4343
*/
4444
const getSubPaths = (p) => {
@@ -65,42 +65,44 @@ const getSubPaths = (p) => {
6565
};
6666

6767
/**
68-
* @type {string} path from repository root
68+
* @returns {string} path from repository root
6969
* @param {string} fullPath filename with full path
7070
* @param {string} repositoryRoot path of repository root
7171
*/
7272
const getPathFromRepositoryRoot = (fullPath, repositoryRoot) =>
7373
fullPath.replace(path.join(repositoryRoot, path.sep), '');
7474

7575
/**
76-
* @type {string} file path in posix style
76+
* @returns {string} file path in posix style
7777
* @param {string} p file path based on the operating system
7878
*/
7979
const toPosixPath = (p) => p.split(path.sep).join(path.posix.sep);
8080

8181
/**
82-
* @type {string} file path without drive letter on windows
82+
* @returns {string} file path without drive letter on windows
8383
* @param {string} p file path on windows
8484
*/
8585
const removeDriveLetter = (p) => p.replace(/^[A-Za-z]:\\/, '');
8686

8787
/**
8888
* Callback for file path
89+
*
8990
* @callback callback
9091
* @param {string} p file path
9192
*/
9293
/**
93-
* @type {callback} piped function
94+
* @returns {callback} piped function
9495
* @param {callback[]} fns callback functions
9596
*/
9697
const pipe =
9798
(...fns) =>
9899
(x) =>
99100
fns.reduce((v, f) => f(v), x);
100101

102+
/** @typedef {module:eslint} ESLint */
101103
/**
102-
* @type {string} file path in posix style
103-
* @param {Rule.RuleContext} context rule eslint context
104+
* @returns {string} file path in posix style
105+
* @param {ESLint.Rule.RuleContext} context rule eslint context
104106
*/
105107
const getFilePath = (context) => {
106108
const pathFromRoot = getPathFromRepositoryRoot(

lib/utils/match.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview Utils about matching rule
2+
* @file Utils about matching rule
33
* @author Duke Luo
44
*/
55
'use strict';
@@ -8,11 +8,11 @@ const micromatch = require('micromatch');
88
const NAMING_CONVENTION = require('../constants/naming-convention');
99

1010
/**
11-
* @type {object | undefined} undefined or object with non-matching file path and naming pattern
12-
* @param filePath
13-
* @param targetFilePathPattern
14-
* @param targetNaming
15-
* @param targetNamingPattern
11+
* @returns {object | undefined} undefined or object with non-matching file path and naming pattern
12+
* @param {string} filePath file path
13+
* @param {string} targetFilePathPattern path pattern of the target file
14+
* @param {string} [targetNaming] target naming
15+
* @param {string} [targetNamingPattern] naming pattern of the target naming
1616
*/
1717
const matchRule = (
1818
filePath,

lib/utils/settings.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview Utils about rule settings
2+
* @file Utils about rule settings
33
* @author Duke Luo
44
*/
55
'use strict';
@@ -8,10 +8,16 @@ const isGlob = require('is-glob');
88
const NAMING_CONVENTION = require('../constants/naming-convention');
99

1010
/**
11-
* @type {string} invalid key or value
12-
* @param settings rule settings configurated by user
13-
* @param keyValidator settings key validator
14-
* @param valueValidator settings value validator
11+
* Validator
12+
*
13+
* @callback validator
14+
* @param {string} p pattern string
15+
*/
16+
/**
17+
* @returns {string | undefined} undefined or invalid field
18+
* @param {object} settings rule settings configurated by user
19+
* @param {validator} keyValidator settings key validator
20+
* @param {validator} valueValidator settings value validator
1521
*/
1622
const checkSettings = (settings, keyValidator, valueValidator) => {
1723
for (const [key, value] of Object.entries(settings)) {
@@ -24,8 +30,8 @@ const checkSettings = (settings, keyValidator, valueValidator) => {
2430
};
2531

2632
/**
27-
* @type {boolean}
28-
* @param namingPattern pattern string
33+
* @returns {boolean} true if pattern is a valid naming pattern
34+
* @param {string} namingPattern pattern string
2935
*/
3036
const namingPatternValidator = (namingPattern) => {
3137
const buildInPatterns = Object.keys(NAMING_CONVENTION);
@@ -34,8 +40,8 @@ const namingPatternValidator = (namingPattern) => {
3440
};
3541

3642
/**
37-
* @type {boolean}
38-
* @param pattern pattern string
43+
* @returns {boolean} true if pattern is a valid glob pattern
44+
* @param {string} pattern pattern string
3945
*/
4046
const globPatternValidator = isGlob;
4147

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)