Skip to content

Commit 1a2293c

Browse files
committed
Adding (and running) eslint
1 parent 251ca4d commit 1a2293c

15 files changed

+192
-119
lines changed

.eslintrc.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module.exports = {
2+
"root": true,
3+
"plugins": ["node"],
4+
"extends": ["eslint:recommended", "plugin:node/recommended"],
5+
"env": {
6+
"node": true,
7+
"es6": true,
8+
},
9+
"parserOptions": { "ecmaVersion": 2017 },
10+
"rules": {
11+
"quotes": ["error", "single"],
12+
"no-undef": "error",
13+
"no-extra-semi": "error",
14+
"semi": "error",
15+
"no-template-curly-in-string": "error",
16+
"no-caller": "error",
17+
"eqeqeq": "error",
18+
"global-require": "off",
19+
"brace-style": "error",
20+
"eol-last": "error",
21+
"indent": ["error", 4, { "SwitchCase": 1 }],
22+
"no-extra-bind": "warn",
23+
"no-empty": "off",
24+
"no-multiple-empty-lines": "error",
25+
"no-multi-spaces": "error",
26+
"no-process-exit": "warn",
27+
"space-in-parens": "error",
28+
"no-trailing-spaces": "error",
29+
"no-use-before-define": "off",
30+
"no-unused-vars": ["error", { "args": "none" }],
31+
"key-spacing": "error",
32+
"space-infix-ops": "error",
33+
"no-unsafe-negation": "error",
34+
"no-loop-func": "warn",
35+
"space-before-function-paren": ["error", "never"],
36+
"space-before-blocks": "error",
37+
"object-curly-spacing": ["error", "always"],
38+
"keyword-spacing": ["error", {
39+
"after": true
40+
}],
41+
"no-console": "off",
42+
"valid-jsdoc": ["error", {"requireParamDescription": false, "requireReturnDescription": false}],
43+
"node/no-unsupported-features": ["error", { version: 6 }],
44+
"node/no-deprecated-api": "error",
45+
"node/no-missing-import": "error",
46+
"node/no-missing-require": [
47+
"error",
48+
{
49+
"allowModules": [
50+
"webpack"
51+
]
52+
}
53+
],
54+
"node/no-unpublished-bin": "error",
55+
"node/no-unpublished-require": "error",
56+
"node/process-exit-as-throw": "error"
57+
}
58+
};
59+

index.js

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const validator = require('./lib/validate-config');
44
const PrettyError = require('pretty-error');
55
const commandConfig = require('./lib/command-config');
66

7-
webpackConfig = new WebpackConfig();
7+
const webpackConfig = new WebpackConfig();
88

99
// determine the environment
1010
let environment = commandConfig.environment;
@@ -26,7 +26,7 @@ module.exports = {
2626
* to the directory where your package.json lives.
2727
*
2828
* @param {string} outputPath
29-
* @returns {exports}
29+
* @return {exports}
3030
*/
3131
setOutputPath(outputPath) {
3232
webpackConfig.setOutputPath(outputPath);
@@ -50,7 +50,7 @@ module.exports = {
5050
* .setManifestKeyPrefix('/build')
5151
*
5252
* @param {string} publicPath
53-
* @returns {exports}
53+
* @return {exports}
5454
*/
5555
setPublicPath(publicPath) {
5656
webpackConfig.setPublicPath(publicPath);
@@ -79,7 +79,7 @@ module.exports = {
7979
* }
8080
*
8181
* @param {string} manifestKeyPrefix
82-
* @returns {exports}
82+
* @return {exports}
8383
*/
8484
setManifestKeyPrefix(manifestKeyPrefix) {
8585
webpackConfig.setManifestKeyPrefix(manifestKeyPrefix);
@@ -101,7 +101,8 @@ module.exports = {
101101
* // guarantee the context is your root directory
102102
* Encore.setContext(__dirname);
103103
*
104-
* @param context
104+
* @param {string} context
105+
* @return {exports}
105106
*/
106107
setContext(context) {
107108
webpackConfig.setContext(context);
@@ -136,7 +137,7 @@ module.exports = {
136137
* False can be passed as an argument to disable the dev server.
137138
*
138139
* @param {string|bool} webpackDevServerUrl
139-
* @returns {exports}
140+
* @return {exports}
140141
*/
141142
useWebpackDevServer(webpackDevServerUrl = null) {
142143
webpackConfig.useWebpackDevServer(webpackDevServerUrl);
@@ -156,18 +157,55 @@ module.exports = {
156157
return this;
157158
},
158159

160+
/**
161+
* Add a "commons" file that holds JS shared by multiple chunks.
162+
*
163+
* @param {string} name The chunk name (e.g. vendor)
164+
* @param {Array} files Array of files to put in the vendor entry
165+
* @return {exports}
166+
*/
159167
createSharedEntry(name, files) {
160168
webpackConfig.createSharedEntry(name, files);
161169

162170
return this;
163171
},
164172

173+
/**
174+
* Automatically make some variables available everywhere!
175+
*
176+
* Usage:
177+
*
178+
* WebpackConfig.autoProvideVariables({
179+
* $: 'jquery',
180+
* jQuery: 'jquery'
181+
* });
182+
*
183+
* Then, whenever $ or jQuery are found in any
184+
* modules, webpack will automatically require
185+
* the "jquery" module so that the variable is available.
186+
*
187+
* This is useful for older packages, that might
188+
* expect jQuery (or something else) to be a global variable.
189+
*
190+
* @param {Array} variables
191+
* @return {exports}
192+
*/
165193
autoProvideVariables(variables) {
166194
webpackConfig.autoProvideVariables(variables);
167195

168196
return this;
169197
},
170198

199+
/**
200+
* Makes jQuery available everywhere. Equivalent to
201+
*
202+
* WebpackConfig.autoProvideVariables({
203+
* $: 'jquery',
204+
* jQuery: 'jquery'
205+
* });
206+
*
207+
* @return {exports}
208+
*/
171209
autoProvidejQuery() {
172210
webpackConfig.autoProvidejQuery();
173211

@@ -180,6 +218,9 @@ module.exports = {
180218
* Once enabled, you must have a postcss.config.js config file.
181219
*
182220
* https://github.com/postcss/postcss-loader
221+
*
222+
* @param {boolean} enabled
223+
* @return {exports}
183224
*/
184225
enablePostCssLoader(enabled = true) {
185226
webpackConfig.enablePostCssLoader(enabled);
@@ -190,8 +231,8 @@ module.exports = {
190231
/**
191232
* Call this if you plan on loading SASS files.
192233
*
193-
* @param enabled
194-
* @returns {exports}
234+
* @param {boolean} enabled
235+
* @return {exports}
195236
*/
196237
enableSassLoader(enabled = true) {
197238
webpackConfig.enableSassLoader(enabled);
@@ -202,8 +243,8 @@ module.exports = {
202243
/**
203244
* Call this if you plan on loading less files.
204245
*
205-
* @param enabled
206-
* @returns {exports}
246+
* @param {boolean} enabled
247+
* @return {exports}
207248
*/
208249
enableLessLoader(enabled = true) {
209250
webpackConfig.enableLessLoader(enabled);
@@ -221,6 +262,7 @@ module.exports = {
221262
* });
222263
*
223264
* @param {function} callback
265+
* @return {exports}
224266
*/
225267
configureBabel(callback) {
226268
webpackConfig.configureBabel(callback);
@@ -232,7 +274,8 @@ module.exports = {
232274
* Should the babel-loader be allowed to load config from
233275
* a .babelrc file?
234276
*
235-
* @param shouldUse
277+
* @param {boolean} shouldUse
278+
* @return {exports}
236279
*/
237280
useBabelRcFile(shouldUse = true) {
238281
webpackConfig.useBabelRcFile(shouldUse);
@@ -267,12 +310,12 @@ module.exports = {
267310
pe.appendStyle({
268311
// hides the full paths below each stack item
269312
'pretty-error > trace': {
270-
display: 'none'
313+
display: 'none'
271314
}
272315
});
273316

274317
console.log(pe.render(error));
275-
process.exit(1);
318+
process.exit(1); // eslint-disable-line
276319
}
277320
}
278321
};

lib/DeleteUnusedEntriesJSPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
1414

1515
// loop over the output files and find the 1 that ends in .js
1616
chunk.files.forEach((filename) => {
17-
if (path.extname(filename) == '.js') {
17+
if (path.extname(filename) === '.js') {
1818
fileDeleteCount++;
1919
// remove the output file
2020
delete compilation.assets[filename];
@@ -26,7 +26,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
2626
// sanity check: make sure 1 file was deleted
2727
// if there's some edge case where multiple .js files
2828
// or 0 .js files might be deleted, I'd rather error
29-
if (fileDeleteCount != 1) {
29+
if (fileDeleteCount !== 1) {
3030
throw new Error(`Problem deleting JS entry for ${chunk.name}: ${fileDeleteCount} files were deleted`);
3131
}
3232
}

lib/WebpackConfig.js

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class WebpackConfig {
2626
}
2727

2828
setEnvironment(environment) {
29-
if (environment != 'production' && environment != 'dev') {
29+
if (environment !== 'production' && environment !== 'dev') {
3030
throw new Error(`Invalid argument "${environment}" passed to setEnvironment. Valid values are production or dev`);
3131
}
3232

@@ -35,7 +35,7 @@ class WebpackConfig {
3535

3636
setContext(context) {
3737
if (null !== this.context) {
38-
throw new Error(`Make sure to call setContext() at the top of your configuration (before adding any entries).`);
38+
throw new Error('Make sure to call setContext() at the top of your configuration (before adding any entries).');
3939
}
4040

4141
this.context = context;
@@ -46,7 +46,7 @@ class WebpackConfig {
4646
// context = cwd(), then find package.json file
4747
const packagesPath = pkgUp.sync(process.cwd());
4848
if (null === packagesPath) {
49-
throw new Error(`Cannot determine webpack context. (Are you executing webpack from a directory outside of your project?). Call setContext() manually at the *top* of your webpack.config.js configuration.`);
49+
throw new Error('Cannot determine webpack context. (Are you executing webpack from a directory outside of your project?). Call setContext() manually at the *top* of your webpack.config.js configuration.');
5050
}
5151

5252
this.context = path.dirname(packagesPath);
@@ -56,7 +56,7 @@ class WebpackConfig {
5656
}
5757

5858
setOutputPath(outputPath) {
59-
if(!path.isAbsolute(outputPath)) {
59+
if (!path.isAbsolute(outputPath)) {
6060
outputPath = path.resolve(this.getContext(), outputPath);
6161
}
6262

@@ -95,16 +95,16 @@ class WebpackConfig {
9595
}
9696

9797
// guarantee a single trailing slash
98-
publicPath = publicPath.replace(/\/$/,"");
99-
publicPath = publicPath+'/';
98+
publicPath = publicPath.replace(/\/$/,'');
99+
publicPath = publicPath + '/';
100100

101101
this.publicPath = publicPath;
102102
}
103103

104104
setManifestKeyPrefix(manifestKeyPrefix) {
105105
// guarantee a single trailing slash, except for blank strings
106106
if (manifestKeyPrefix !== '') {
107-
manifestKeyPrefix = manifestKeyPrefix.replace(/\/$/, "");
107+
manifestKeyPrefix = manifestKeyPrefix.replace(/\/$/, '');
108108
manifestKeyPrefix = manifestKeyPrefix + '/';
109109
}
110110

@@ -138,8 +138,8 @@ class WebpackConfig {
138138
}
139139

140140
// guarantee a single trailing slash
141-
webpackDevServerUrl = webpackDevServerUrl.replace(/\/$/,"");
142-
webpackDevServerUrl = webpackDevServerUrl+'/';
141+
webpackDevServerUrl = webpackDevServerUrl.replace(/\/$/,'');
142+
webpackDevServerUrl = webpackDevServerUrl + '/';
143143

144144
this.webpackDevServerUrl = webpackDevServerUrl;
145145
}
@@ -154,7 +154,7 @@ class WebpackConfig {
154154
// if we're using webpack-dev-server, use it & add the publicPath
155155
if (this.webpackDevServerUrl) {
156156
// avoid 2 middle slashes
157-
return this.webpackDevServerUrl.replace(/\/$/,"") + this.publicPath;
157+
return this.webpackDevServerUrl.replace(/\/$/,'') + this.publicPath;
158158
}
159159

160160
return this.publicPath;
@@ -205,15 +205,10 @@ class WebpackConfig {
205205
this.allowBabelRcFile = shouldUse;
206206
}
207207

208-
/**
209-
*
210-
* @param name The chunk name (e.g. vendor)
211-
* @param files Array of files to put in the vendor entry
212-
*/
213208
createSharedEntry(name, files) {
214209
// don't allow to call this twice
215210
if (this.sharedCommonsEntryName) {
216-
throw new Error('createSharedEntry() cannot be called multiple times: you can only create *one* shared entry.')
211+
throw new Error('createSharedEntry() cannot be called multiple times: you can only create *one* shared entry.');
217212
}
218213

219214
this.sharedCommonsEntryName = name;
@@ -241,28 +236,9 @@ class WebpackConfig {
241236
this.cleanupOutput = true;
242237
}
243238

244-
/**
245-
* Automatically make some variables available everywhere!
246-
*
247-
* Usage:
248-
*
249-
* WebpackConfig.autoProvideVariables({
250-
* $: 'jquery',
251-
* jQuery: 'jquery'
252-
* });
253-
*
254-
* Then, whenever $ or jQuery are found in any
255-
* modules, webpack will automatically require
256-
* the "jquery" module so that the variable is available.
257-
*
258-
* This is useful for older packages, that might
259-
* expect jQuery (or something else) to be a global variable.
260-
*
261-
* @param variables
262-
*/
263239
autoProvideVariables(variables) {
264240
// do a few sanity checks, so we can give better user errors
265-
if (typeof variables == 'string' || Array.isArray(variables)) {
241+
if (typeof variables === 'string' || Array.isArray(variables)) {
266242
throw new Error('Invalid argument passed to autoProvideVariables: you must pass an object map - e.g. { $: "jquery" }');
267243
}
268244

@@ -274,14 +250,6 @@ class WebpackConfig {
274250
);
275251
}
276252

277-
/**
278-
* Makes jQuery available everywhere. Equivalent to
279-
*
280-
* WebpackConfig.autoProvideVariables({
281-
* $: 'jquery',
282-
* jQuery: 'jquery'
283-
* });
284-
*/
285253
autoProvidejQuery() {
286254
this.autoProvideVariables({
287255
$: 'jquery',

0 commit comments

Comments
 (0)