Skip to content

Commit 434b86c

Browse files
ghussedevongovett
authored andcommitted
Uses ESLint to catch errors and fixes ESLint errors #173 (#180)
* Uses ESLint to catch errors and fixes ESLint errors #173 * Changes ESLint configuration to allows usage of console * Launches npm run lint before git commit * Adds missing ESLint config files * Runs ESLint in AppVeyor * Fixes a regression introduced previously, fixes new warnings * Fixes new ESLint errors introduced in master * Specifies ecmaVersion=5 in builtins and fixes errors in index.js
1 parent 7618677 commit 434b86c

Some content is hidden

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

45 files changed

+610
-88
lines changed

.eslintignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ESLint does not support both
2+
# - import used as a function, and
3+
# - the export statement
4+
# in the same file
5+
6+
/test/integration/dynamic/index.js
7+
/test/integration/dynamic-css/index.js
8+
/test/integration/dynamic-esm/index.js
9+
/test/integration/dynamic-hoist/index.js
10+
/test/integration/dynamic-references-raw/index.js
11+
/test/integration/dynamic-references-raw/local.js
12+
/test/integration/hmr-dynamic/index.js
13+
14+
# Generated by the build
15+
lib
16+
dist
17+
/test/dist
18+
/test/input
19+
20+
coverage

.eslintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"parserOptions": {
4+
"ecmaVersion": 8
5+
},
6+
"env": {
7+
"node": true,
8+
"es6": true
9+
}
10+
}

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ node_js:
44
# - '6'
55
- '8'
66
cache: yarn
7-
script: yarn test
7+
script:
8+
- yarn test
9+
- yarn lint
810
sudo: false

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ test_script:
1616
- yarn --version
1717
# run tests
1818
- yarn test
19+
# run ESlint
20+
- yarn lint
1921

2022
cache:
2123
- "%LOCALAPPDATA%\\Yarn"

bin/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../.eslintrc.json",
3+
"rules": {
4+
"no-console": 0
5+
}
6+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"babel-preset-env": "^1.6.1",
4646
"coffeescript": "^2.0.3",
4747
"cross-env": "^5.1.1",
48+
"eslint": "^4.13.0",
4849
"husky": "^0.14.3",
4950
"less": "^2.7.2",
5051
"lint-staged": "^6.0.0",
@@ -65,7 +66,8 @@
6566
"format": "prettier --write './{src,bin,test}/**/*.{js,json,md}'",
6667
"build": "babel src -d lib",
6768
"prepublish": "yarn build",
68-
"precommit": "lint-staged",
69+
"precommit": "npm run lint && lint-staged",
70+
"lint": "eslint .",
6971
"postinstall":
7072
"node -e \"console.log('\\u001b[35m\\u001b[1mLove Parcel? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/parcel/donate\\u001b[0m')\""
7173
},

src/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../.eslintrc.json",
3+
"rules": {
4+
"no-console": 0
5+
}
6+
}

src/Asset.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ class Asset {
7171
from = this.name;
7272
}
7373

74-
let resolved = path
75-
.resolve(path.dirname(from), url)
76-
.replace(/[\?#].*$/, '');
77-
74+
let resolved = path.resolve(path.dirname(from), url).replace(/[?#].*$/, '');
7875
this.addDependency(
7976
'./' + path.relative(path.dirname(this.name), resolved),
8077
Object.assign({dynamic: true}, opts)

src/Bundle.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const Path = require('path');
2-
const fs = require('fs');
32
const crypto = require('crypto');
43

54
/**

src/Bundler.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const fs = require('./utils/fs');
22
const Resolver = require('./Resolver');
33
const Parser = require('./Parser');
44
const WorkerFarm = require('./WorkerFarm');
5-
const worker = require('./utils/promisify')(require('./worker.js'));
65
const Path = require('path');
76
const Bundle = require('./Bundle');
87
const {FSWatcher} = require('chokidar');
@@ -13,7 +12,6 @@ const {EventEmitter} = require('events');
1312
const Logger = require('./Logger');
1413
const PackagerRegistry = require('./packagers');
1514
const localRequire = require('./utils/localRequire');
16-
const customErrors = require('./utils/customErrors');
1715
const config = require('./utils/config');
1816

1917
/**
@@ -273,8 +271,10 @@ class Bundler extends EventEmitter {
273271
try {
274272
return await this.resolveAsset(dep.name, asset.name);
275273
} catch (err) {
276-
if (err.message.indexOf(`Cannot find module '${dep.name}'`) === 0) {
277-
err.message = `Cannot resolve dependency '${dep.name}'`;
274+
let thrown = err;
275+
276+
if (thrown.message.indexOf(`Cannot find module '${dep.name}'`) === 0) {
277+
thrown.message = `Cannot resolve dependency '${dep.name}'`;
278278

279279
// Add absolute path to the error message if the dependency specifies a relative path
280280
if (dep.name.startsWith('.')) {
@@ -285,13 +285,13 @@ class Bundler extends EventEmitter {
285285
// Generate a code frame where the dependency was used
286286
if (dep.loc) {
287287
await asset.loadIfNeeded();
288-
err.loc = dep.loc;
289-
err = asset.generateErrorMessage(err);
288+
thrown.loc = dep.loc;
289+
thrown = asset.generateErrorMessage(thrown);
290290
}
291291

292-
err.fileName = asset.name;
292+
thrown.fileName = asset.name;
293293
}
294-
throw err;
294+
throw thrown;
295295
}
296296
}
297297

0 commit comments

Comments
 (0)