Skip to content

Commit 7cb2bdb

Browse files
style(/*): Lint all the things!
Linting the whole app so its less of a pain to use commitizen
1 parent cbbe10c commit 7cb2bdb

File tree

16 files changed

+119
-97
lines changed

16 files changed

+119
-97
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ root = true
88
charset = utf-8
99
end_of_line = lf
1010
insert_final_newline = true
11-
indent_style = tab
11+
indent_style = space
1212
indent_size = 4
1313

1414
# Matches the exact files either package.json or .travis.yml

.eslintrc.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,14 @@ module.exports = {
88
sourceType: 'module',
99
allowImportExportEverywhere: false
1010
},
11-
extends: ['airbnb']
12-
}
11+
extends: ['airbnb'],
12+
env: {
13+
'browser': true,
14+
},
15+
rules: {
16+
'no-param-reassign': 0,
17+
'func-names': 0,
18+
'no-underscore-dangle': 0,
19+
'no-restricted-syntax': 0,
20+
}
21+
};

package-lock.json

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

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"start": "npm run build -- -w",
1616
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
1717
"clean": "del-cli dist",
18-
"lint": "eslint --cache src test",
18+
"lint": "eslint --cache --fix src test",
1919
"prebuild": "npm run clean",
2020
"prepublish": "npm run build",
2121
"release": "standard-version",
@@ -25,11 +25,12 @@
2525
"test": "jest",
2626
"test:watch": "jest --watch",
2727
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
28+
"test:example": "npm run build && webpack-dev-server test/manual/src/index.js --config test/manual/webpack.config.js",
2829
"ci:lint": "npm run lint && npm run security",
2930
"ci:test": "npm run test -- --runInBand",
3031
"ci:coverage": "npm run test:coverage -- --runInBand",
3132
"below:zack": "echo 1",
32-
"build:example": "(cd example && webpack)",
33+
"build:example": "npm run build && webpack-dev-server test/manual/src/index.js --open --config test/manual/webpack.config.js",
3334
"cm": "git-cz",
3435
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
3536
"travis": "npm run cover -- --report lcovonly",
@@ -41,6 +42,8 @@
4142
"dependencies": {
4243
"@webpack-contrib/schema-utils": "^1.0.0-beta.0",
4344
"loader-utils": "^1.1.0",
45+
"lodash": "^4.17.10",
46+
"normalize-url": "^3.0.0",
4447
"webpack-sources": "^1.1.0"
4548
},
4649
"devDependencies": {

src/hotLoader.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const path = require('path');
2-
32
const loaderUtils = require('loader-utils');
43

54
const defaultOptions = {
65
fileMap: '{fileName}',
76
};
8-
module.exports = function (content) {
7+
8+
function hotReload(content) {
99
this.cacheable();
1010
const options = Object.assign(
1111
{},
@@ -24,4 +24,6 @@ module.exports = function (content) {
2424
module.hot.accept(undefined, cssReload);
2525
}
2626
`;
27-
};
27+
}
28+
29+
module.exports = hotReload;

src/hotModuleReplacement.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ function updateCss(el, url) {
6969
el.parentNode.appendChild(newEl);
7070
}
7171

72+
function getReloadUrl(href, src) {
73+
href = normalizeUrl(href, { stripWWW: false });
74+
let ret;
75+
src.some((url) => { // eslint-disable-line array-callback-return
76+
if (href.indexOf(src) > -1) {
77+
ret = url;
78+
}
79+
});
80+
return ret;
81+
}
82+
7283
function reloadStyle(src) {
7384
const elements = document.querySelectorAll('link');
7485
let loaded = false;
@@ -86,17 +97,6 @@ function reloadStyle(src) {
8697
return loaded;
8798
}
8899

89-
function getReloadUrl(href, src) {
90-
href = normalizeUrl(href, { stripWWW: false });
91-
let ret;
92-
src.some((url) => {
93-
if (href.indexOf(src) > -1) {
94-
ret = url;
95-
}
96-
});
97-
return ret;
98-
}
99-
100100
function reloadAll() {
101101
const elements = document.querySelectorAll('link');
102102
forEach.call(elements, (el) => {
@@ -106,21 +106,19 @@ function reloadAll() {
106106
}
107107

108108
module.exports = function (moduleId, options) {
109-
let getScriptSrc;
110-
111109
if (noDocument) {
112110
return noop;
113111
}
114112

115-
getScriptSrc = getCurrentScriptUrl(moduleId);
113+
const getScriptSrc = getCurrentScriptUrl(moduleId);
116114

117115
function update() {
118116
const src = getScriptSrc(options.fileMap);
119117
const reloaded = reloadStyle(src);
120118
if (reloaded) {
121-
console.log('[HMR] css reload %s', src.join(' '));
119+
console.log('[HMR] css reload %s', src.join(' ')); // eslint-disable-line no-console
122120
} else {
123-
console.log('[HMR] Reload all css');
121+
console.log('[HMR] Reload all css'); // eslint-disable-line no-console
124122
reloadAll();
125123
}
126124
}

src/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CssDependency extends webpack.Dependency {
3838
}
3939

4040
class CssDependencyTemplate {
41-
apply() {
41+
apply() { // eslint-disable-line class-methods-use-this
4242
}
4343
}
4444

@@ -81,7 +81,7 @@ class CssModule extends webpack.Module {
8181
this.sourceMap = module.sourceMap;
8282
}
8383

84-
needRebuild() {
84+
needRebuild() { // eslint-disable-line class-methods-use-this
8585
return true;
8686
}
8787

@@ -100,12 +100,12 @@ class CssModule extends webpack.Module {
100100
}
101101

102102
class CssModuleFactory {
103-
create({ dependencies: [dependency] }, callback) {
103+
create({ dependencies: [dependency] }, callback) { // eslint-disable-line class-methods-use-this
104104
callback(null, new CssModule(dependency));
105105
}
106106
}
107107

108-
class MiniCssExtractPlugin {
108+
class ExtractCssChunks {
109109
constructor(options) {
110110
this.options = Object.assign(
111111
{
@@ -136,7 +136,6 @@ class MiniCssExtractPlugin {
136136
if (rule.use) {
137137
const isMiniCss = rule.use.some((l) => {
138138
const needle = l.loader || l;
139-
console.log('NEEDLE:', needle, 'HAS:', needle.includes(pluginName));
140139
return needle.includes(pluginName);
141140
});
142141
if (isMiniCss) {
@@ -387,7 +386,7 @@ class MiniCssExtractPlugin {
387386
});
388387
}
389388

390-
getCssChunkObject(mainChunk) {
389+
getCssChunkObject(mainChunk) { // eslint-disable-line class-methods-use-this
391390
const obj = {};
392391
for (const chunk of mainChunk.getAllAsyncChunks()) {
393392
for (const module of chunk.modulesIterable) {
@@ -400,7 +399,7 @@ class MiniCssExtractPlugin {
400399
return obj;
401400
}
402401

403-
renderContentAsset(modules, requestShortener) {
402+
renderContentAsset(modules, requestShortener) { // eslint-disable-line class-methods-use-this
404403
modules.sort((a, b) => a.index2 - b.index2);
405404
const source = new ConcatSource();
406405
const externalsSource = new ConcatSource();
@@ -447,6 +446,6 @@ class MiniCssExtractPlugin {
447446
}
448447
}
449448

450-
MiniCssExtractPlugin.loader = require.resolve('./loader');
449+
ExtractCssChunks.loader = require.resolve('./loader');
451450

452-
export default MiniCssExtractPlugin;
451+
export default ExtractCssChunks;

src/loader.js

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const NS = path.dirname(fs.realpathSync(__filename));
1313

1414
const exec = (loaderContext, code, filename) => {
1515
const module = new NativeModule(filename, loaderContext);
16-
module.paths = NativeModule._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle
16+
17+
// eslint-disable-next-line no-underscore-dangle
18+
module.paths = NativeModule._nodeModulePaths(loaderContext.context);
1719
module.filename = filename;
1820
module._compile(code, filename); // eslint-disable-line no-underscore-dangle
1921
return module.exports;
@@ -34,65 +36,65 @@ export function pitch(request) {
3436
this.addDependency(this.resourcePath);
3537
const childFilename = '*'; // eslint-disable-line no-path-concat
3638
const publicPath =
37-
typeof query.publicPath === 'string'
38-
? query.publicPath
39-
: this._compilation.outputOptions.publicPath;
39+
typeof query.publicPath === 'string'
40+
? query.publicPath
41+
: this._compilation.outputOptions.publicPath;
4042
const outputOptions = {
4143
filename: childFilename,
4244
publicPath,
4345
};
4446
const childCompiler = this._compilation.createChildCompiler(
45-
`extract-css-chunks-webpack-plugin ${request}`,
46-
outputOptions,
47-
);
47+
`extract-css-chunks-webpack-plugin ${request}`,
48+
outputOptions,
49+
);
4850
new NodeTemplatePlugin(outputOptions).apply(childCompiler);
4951
new LibraryTemplatePlugin(null, 'commonjs2').apply(childCompiler);
5052
new NodeTargetPlugin().apply(childCompiler);
5153
new SingleEntryPlugin(
52-
this.context,
53-
`!!${request}`,
54-
'extract-css-chunks-webpack-plugin',
55-
).apply(childCompiler);
54+
this.context,
55+
`!!${request}`,
56+
'extract-css-chunks-webpack-plugin',
57+
).apply(childCompiler);
5658
new LimitChunkCountPlugin({ maxChunks: 1 }).apply(childCompiler);
57-
// We set loaderContext[NS] = false to indicate we already in
58-
// a child compiler so we don't spawn another child compilers from there.
59+
// We set loaderContext[NS] = false to indicate we already in
60+
// a child compiler so we don't spawn another child compilers from there.
5961
childCompiler.hooks.thisCompilation.tap(
60-
'extract-css-chunks-webpack-plugin loader',
61-
(compilation) => {
62-
compilation.hooks.normalModuleLoader.tap(
6362
'extract-css-chunks-webpack-plugin loader',
64-
(loaderContext, module) => {
65-
loaderContext[NS] = false; // eslint-disable-line no-param-reassign
66-
if (module.request === request) {
67-
module.loaders = loaders.map(loader =>
68-
// eslint-disable-line no-param-reassign
69-
({
70-
loader: loader.path,
71-
options: loader.options,
72-
ident: loader.ident,
73-
}));
74-
}
63+
(compilation) => {
64+
compilation.hooks.normalModuleLoader.tap(
65+
'extract-css-chunks-webpack-plugin loader',
66+
(loaderContext, module) => {
67+
loaderContext[NS] = false; // eslint-disable-line no-param-reassign
68+
if (module.request === request) {
69+
module.loaders = loaders.map(loader =>
70+
// eslint-disable-line no-param-reassign
71+
({
72+
loader: loader.path,
73+
options: loader.options,
74+
ident: loader.ident,
75+
}));
76+
}
77+
},
78+
);
7579
},
76-
);
77-
},
78-
);
80+
);
7981

8082
let source;
8183
childCompiler.hooks.afterCompile.tap(
82-
'extract-css-chunks-webpack-plugin',
83-
(compilation) => {
84-
source =
85-
compilation.assets[childFilename] &&
86-
compilation.assets[childFilename].source();
84+
'extract-css-chunks-webpack-plugin',
85+
(compilation) => {
86+
source =
87+
compilation.assets[childFilename] &&
88+
compilation.assets[childFilename].source();
8789

88-
// Remove all chunk assets
89-
compilation.chunks.forEach((chunk) => {
90-
chunk.files.forEach((file) => {
91-
delete compilation.assets[file]; // eslint-disable-line no-param-reassign
92-
});
93-
});
94-
},
95-
);
90+
// Remove all chunk assets
91+
compilation.chunks.forEach((chunk) => {
92+
chunk.files.forEach((file) => {
93+
delete compilation.assets[file]; // eslint-disable-line no-param-reassign
94+
});
95+
});
96+
},
97+
);
9698

9799
const callback = this.async();
98100
childCompiler.runAsChild((err, entries, compilation) => {
@@ -108,7 +110,7 @@ export function pitch(request) {
108110
this.addContextDependency(dep);
109111
}, this);
110112
if (!source) {
111-
return callback(new Error("Didn't get a result from child compiler"));
113+
return callback(new Error('Didn\'t get a result from child compiler'));
112114
}
113115
let text;
114116
let locals;
@@ -140,4 +142,6 @@ export function pitch(request) {
140142
return callback(null, resultSource);
141143
});
142144
}
143-
export default function () {}
145+
146+
export default function () {
147+
}

0 commit comments

Comments
 (0)