Skip to content

Commit 3462433

Browse files
committed
Migrate to eslint-plugin-jsdoc
The deprecated valid-jsdoc rule of eslint does not support using typescript syntax for types, while it allows being more precise about types in a much more readable way than using the older jsdoc syntax with separate typedef or callback definitions. The plugin also implements more rules than what valid-jsdoc does.
1 parent 17ce5fd commit 3462433

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+114
-67
lines changed

.eslintrc.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
module.exports = {
1111
"root": true,
12-
"plugins": ["node", "header"],
13-
"extends": ["eslint:recommended", "plugin:node/recommended"],
12+
"plugins": ["node", "header", "jsdoc"],
13+
"extends": ["eslint:recommended", "plugin:node/recommended", "plugin:jsdoc/recommended"],
1414
"env": {
1515
"node": true,
1616
"es6": true,
@@ -48,7 +48,12 @@ module.exports = {
4848
"after": true
4949
}],
5050
"no-console": "off",
51-
"valid-jsdoc": ["error", { "requireParamDescription": false, "requireReturnDescription": false }],
51+
"jsdoc/require-jsdoc": "off",
52+
"jsdoc/require-param-description": "off",
53+
"jsdoc/require-property-description": "off",
54+
"jsdoc/require-returns-description": "off",
55+
// We use typescript-like literal `false` for some signatures, which is not yet supported natively by eslint-plugin-jsdoc
56+
"jsdoc/no-undefined-types": ["error", { definedTypes: ["false"] }],
5257
"node/no-unsupported-features": ["error", { version: 8 }],
5358
"node/no-deprecated-api": "error",
5459
"node/no-missing-import": "error",
@@ -65,6 +70,11 @@ module.exports = {
6570
"node/process-exit-as-throw": "error",
6671
"header/header": [2, "block", { "pattern": "This file is part of the Symfony Webpack Encore package" }]
6772
},
73+
"settings": {
74+
"jsdoc": {
75+
"mode": "typescript"
76+
}
77+
},
6878
"overrides": [
6979
{
7080
"files": [".eslintrc.js"],

index.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Encore {
114114
* })
115115
* ```
116116
*
117-
* @param {function} definePluginOptionsCallback
117+
* @param {Function} definePluginOptionsCallback
118118
* @returns {Encore}
119119
*/
120120
configureDefinePlugin(definePluginOptionsCallback = () => {}) {
@@ -135,7 +135,7 @@ class Encore {
135135
* })
136136
* ```
137137
*
138-
* @param {function} friendlyErrorsPluginOptionsCallback
138+
* @param {Function} friendlyErrorsPluginOptionsCallback
139139
* @returns {Encore}
140140
*/
141141
configureFriendlyErrorsPlugin(friendlyErrorsPluginOptionsCallback = () => {}) {
@@ -156,7 +156,7 @@ class Encore {
156156
* })
157157
* ```
158158
*
159-
* @param {function} manifestPluginOptionsCallback
159+
* @param {Function} manifestPluginOptionsCallback
160160
* @returns {Encore}
161161
*/
162162
configureManifestPlugin(manifestPluginOptionsCallback = () => {}) {
@@ -182,7 +182,7 @@ class Encore {
182182
* })
183183
* ```
184184
*
185-
* @param {function} terserPluginOptionsCallback
185+
* @param {Function} terserPluginOptionsCallback
186186
* @returns {Encore}
187187
*/
188188
configureTerserPlugin(terserPluginOptionsCallback = () => {}) {
@@ -206,7 +206,7 @@ class Encore {
206206
* })
207207
* ```
208208
*
209-
* @param {function} optimizeCssPluginOptionsCallback
209+
* @param {Function} optimizeCssPluginOptionsCallback
210210
* @returns {Encore}
211211
*/
212212
configureOptimizeCssPlugin(optimizeCssPluginOptionsCallback = () => {}) {
@@ -350,7 +350,7 @@ class Encore {
350350
* })
351351
* ```
352352
*
353-
* @param {Object<string, string>} aliases
353+
* @param {object<string, string>} aliases
354354
*
355355
* @returns {Encore}
356356
*/
@@ -746,7 +746,7 @@ class Encore {
746746
* This is useful for older packages, that might
747747
* expect jQuery (or something else) to be a global variable.
748748
*
749-
* @param {Object<string, string|string[]>} variables
749+
* @param {object<string, string | string[]>} variables
750750
* @returns {Encore}
751751
*/
752752
autoProvideVariables(variables) {
@@ -1237,7 +1237,6 @@ class Encore {
12371237
* Supported options:
12381238
* * {boolean} lintVue (default=false)
12391239
* Configure the loader to lint `.vue` files
1240-
* ```
12411240
*
12421241
* @param {string|object|(function(object): object|void)} eslintLoaderOptionsOrCallback
12431242
* @param {{lintVue?: boolean}} encoreOptions
@@ -1331,6 +1330,7 @@ class Encore {
13311330
*
13321331
* Internally, this disables the mini-css-extract-plugin
13331332
* and uses the style-loader instead.
1333+
*
13341334
* @param {boolean} disabled
13351335
* @returns {Encore}
13361336
*/
@@ -1412,7 +1412,7 @@ class Encore {
14121412
* falsy value the file-loader will be used instead.
14131413
*
14141414
* @param {{images?: false|object, fonts?: false|object}} urlLoaderOptions
1415-
* @return {Encore}
1415+
* @returns {Encore}
14161416
*/
14171417
configureUrlLoader(urlLoaderOptions = {}) {
14181418
webpackConfig.configureUrlLoader(urlLoaderOptions);
@@ -1440,7 +1440,7 @@ class Encore {
14401440
*
14411441
* @param {string} name
14421442
* @param {function(webpack.RuleSetRule): webpack.RuleSetRule|void} callback
1443-
* @return {Encore}
1443+
* @returns {Encore}
14441444
*/
14451445
configureLoaderRule(name, callback) {
14461446
webpackConfig.configureLoaderRule(name, callback);
@@ -1633,31 +1633,31 @@ class Encore {
16331633

16341634
/**
16351635
* @deprecated
1636-
* @return {void}
1636+
* @returns {void}
16371637
*/
16381638
configureExtractTextPlugin() {
16391639
throw new Error('The configureExtractTextPlugin() method was removed from Encore. The underlying plugin was removed from Webpack 4.');
16401640
}
16411641

16421642
/**
16431643
* @deprecated
1644-
* @return {void}
1644+
* @returns {void}
16451645
*/
16461646
enableCoffeeScriptLoader() {
16471647
throw new Error('The enableCoffeeScriptLoader() method and CoffeeScript support was removed from Encore due to support problems with Webpack 4. If you are interested in this feature, please submit a pull request!');
16481648
}
16491649

16501650
/**
16511651
* @deprecated
1652-
* @return {void}
1652+
* @returns {void}
16531653
*/
16541654
configureUglifyJsPlugin() {
16551655
throw new Error('The configureUglifyJsPlugin() method was removed from Encore due to uglify-js dropping ES6+ support in its latest version. Please use configureTerserPlugin() instead.');
16561656
}
16571657

16581658
/**
16591659
* @deprecated
1660-
* @return {void}
1660+
* @returns {void}
16611661
*/
16621662
configureLoaderOptionsPlugin() {
16631663
throw new Error('The configureLoaderOptionsPlugin() method was removed from Encore. The underlying plugin should not be needed anymore unless you are using outdated loaders. If that\'s the case you can still add it using addPlugin().');
@@ -1667,6 +1667,7 @@ class Encore {
16671667
/**
16681668
* Proxy the API in order to prevent calls to most of its methods
16691669
* if the webpackConfig object hasn't been initialized yet.
1670+
*
16701671
* @type {Encore}
16711672
*/
16721673
module.exports = EncoreProxy.createProxy(new Encore());

lib/WebpackConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const regexpEscaper = require('./utils/regexp-escaper');
1818

1919
/**
2020
* @param {RuntimeConfig|null} runtimeConfig
21-
* @return {void}
21+
* @returns {void}
2222
*/
2323
function validateRuntimeConfig(runtimeConfig) {
2424
// if you're using the encore executable, these things should never happen
@@ -37,7 +37,7 @@ function validateRuntimeConfig(runtimeConfig) {
3737

3838
/**
3939
* @param {RuntimeConfig} runtimeConfig
40-
* @return {void}
40+
* @returns {void}
4141
*/
4242
function checkPackageJson(runtimeConfig) {
4343
// Display a warning if webpack is listed as a [dev-]dependency

lib/config-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class ConfigGenerator {
669669
/**
670670
* @param {WebpackConfig} webpackConfig A configured WebpackConfig object
671671
*
672-
* @return {*} The final webpack config object
672+
* @returns {*} The final webpack config object
673673
*/
674674
module.exports = function(webpackConfig) {
675675
const generator = new ConfigGenerator(webpackConfig);

lib/config/parse-runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const babel = require('@babel/core');
1616

1717
/**
1818
* @param {object} argv
19-
* @param {String} cwd
19+
* @param {string} cwd
2020
* @returns {RuntimeConfig}
2121
*/
2222
module.exports = function(argv, cwd) {

lib/config/path-util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
* Determines the "contentBase" to use for the devServer.
1818
*
1919
* @param {WebpackConfig} webpackConfig
20-
* @return {String}
20+
* @returns {string}
2121
*/
2222
getContentBase(webpackConfig) {
2323
// strip trailing slash (for Unix or Windows)
@@ -57,7 +57,7 @@ module.exports = {
5757
* Returns the output path, but as a relative string (e.g. web/build)
5858
*
5959
* @param {WebpackConfig} webpackConfig
60-
* @return {String}
60+
* @returns {string}
6161
*/
6262
getRelativeOutputPath(webpackConfig) {
6363
return webpackConfig.outputPath.replace(webpackConfig.getContext() + path.sep, '');
@@ -70,7 +70,7 @@ module.exports = {
7070
* ok to use the publicPath as the manifestKeyPrefix.
7171
*
7272
* @param {WebpackConfig} webpackConfig
73-
* @return {void}
73+
* @returns {void}
7474
*/
7575
validatePublicPathAndManifestKeyPrefix(webpackConfig) {
7676
if (webpackConfig.manifestKeyPrefix !== null) {

lib/loaders/babel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const applyOptionsCallback = require('../utils/apply-options-callback');
1616
module.exports = {
1717
/**
1818
* @param {WebpackConfig} webpackConfig
19-
* @return {Array} of loaders to use for Babel
19+
* @returns {Array} of loaders to use for Babel
2020
*/
2121
getLoaders(webpackConfig) {
2222
let babelConfig = {
@@ -106,7 +106,7 @@ module.exports = {
106106

107107
/**
108108
* @param {WebpackConfig} webpackConfig
109-
* @return {RegExp} to use for eslint-loader `test` rule
109+
* @returns {RegExp} to use for eslint-loader `test` rule
110110
*/
111111
getTest(webpackConfig) {
112112
const extensions = [

lib/loaders/css-extract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
*
2020
* @param {WebpackConfig} webpackConfig
2121
* @param {Array} loaders An array of some style loaders
22-
* @return {Array}
22+
* @returns {Array}
2323
*/
2424
prependLoaders(webpackConfig, loaders) {
2525
if (!webpackConfig.extractCss) {

lib/loaders/css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
/**
1818
* @param {WebpackConfig} webpackConfig
1919
* @param {boolean} useCssModules
20-
* @return {Array} of loaders to use for CSS files
20+
* @returns {Array} of loaders to use for CSS files
2121
*/
2222
getLoaders(webpackConfig, useCssModules = false) {
2323
const usePostCssLoader = webpackConfig.usePostCssLoader;

lib/loaders/eslint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function isMissingConfigError(e) {
2424
module.exports = {
2525
/**
2626
* @param {WebpackConfig} webpackConfig
27-
* @return {Object} of options to use for eslint-loader options.
27+
* @returns {object} of options to use for eslint-loader options.
2828
*/
2929
getOptions(webpackConfig) {
3030
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('eslint');
@@ -73,7 +73,7 @@ Install ${chalk.yellow('babel-eslint')} to prevent potential parsing issues: ${p
7373

7474
/**
7575
* @param {WebpackConfig} webpackConfig
76-
* @return {RegExp} to use for eslint-loader `test` rule
76+
* @returns {RegExp} to use for eslint-loader `test` rule
7777
*/
7878
getTest(webpackConfig) {
7979
const extensions = ['jsx?'];

0 commit comments

Comments
 (0)