-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uses ESLint to catch errors and fixes ESLint errors #173 #180
Changes from 1 commit
96469cb
c850a1e
e103804
c574900
fe571bf
8b492f2
d2738bd
d919fa9
526afc8
26aabe0
dd55256
944f360
ec0e1c6
9c1215c
437b385
2e81db0
7a0ad22
7b1714e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# ESLint does not support both | ||
# - import used as a function, and | ||
# - the export statement | ||
# in the same file | ||
|
||
/test/integration/dynamic/index.js | ||
/test/integration/dynamic-css/index.js | ||
/test/integration/dynamic-esm/index.js | ||
/test/integration/dynamic-hoist/index.js | ||
/test/integration/hmr-dynamic/index.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting this to 8 will result in some features not supported by Node 6 to no longer be caught by ESLint, so we should beware of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, babel seem used everywhere in parcel. It allows to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, you're right. The whole codebase is later transpiled using Babel. This should be okay. Thanks for the clarification 😅 |
||
}, | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,7 @@ node_js: | |
# - '6' | ||
- '8' | ||
cache: yarn | ||
script: yarn test | ||
script: | ||
- yarn test | ||
- yarn lint | ||
sudo: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,13 +62,15 @@ program | |
}); | ||
|
||
program.on('--help', function() { | ||
/* eslint-disable no-console */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a CLI, should we just allow console globally in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll change that |
||
console.log(''); | ||
console.log( | ||
' Run `' + | ||
chalk.bold('parcel help <command>') + | ||
'` for more information on specific commands' | ||
); | ||
console.log(''); | ||
/* eslint-enable no-console */ | ||
}); | ||
|
||
// Make serve the default command | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"cross-env": "^5.1.1", | ||
"eslint": "^4.13.0", | ||
"husky": "^0.14.3", | ||
"less": "^2.7.2", | ||
"lint-staged": "^6.0.0", | ||
|
@@ -62,7 +63,8 @@ | |
"format": "prettier --write './{src,bin,test}/**/*.{js,json,md}'", | ||
"build": "babel src -d lib", | ||
"prepublish": "yarn build", | ||
"precommit": "lint-staged" | ||
"precommit": "lint-staged", | ||
"lint": "eslint ." | ||
}, | ||
"bin": { | ||
"parcel": "bin/cli.js" | ||
|
@@ -71,6 +73,10 @@ | |
"node": ">= 6.0.0" | ||
}, | ||
"lint-staged": { | ||
"*.{js,json,md}": ["prettier --write", "git add"] | ||
"*.{js,json,md}": [ | ||
"prettier --write", | ||
"eslint --fix", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it should instead do an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. woops. Thanks. I'll change that |
||
"git add" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
const Parser = require('./Parser'); | ||
const path = require('path'); | ||
const fs = require('./utils/fs'); | ||
const objectHash = require('./utils/objectHash'); | ||
|
@@ -73,7 +72,7 @@ class Asset { | |
|
||
let resolved = path | ||
.resolve(path.dirname(from), url) | ||
.replace(/[\?#].*$/, ''); | ||
.replace(/[?#].*$/, ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very good with regex, so simply ignore if I'm being stupid here, but looks like ESLint removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, they are the same.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah @brandon93s I'm the type that has to look up SO for the simplest regex's. 😆 but thanks for looking into it! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep: ESLint was complaining about unecessary escapes. |
||
this.addDependency( | ||
'./' + path.relative(path.dirname(this.name), resolved), | ||
Object.assign({dynamic: true}, opts) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
const Path = require('path'); | ||
const fs = require('fs'); | ||
const crypto = require('crypto'); | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ const fs = require('./utils/fs'); | |
const Resolver = require('./Resolver'); | ||
const Parser = require('./Parser'); | ||
const WorkerFarm = require('./WorkerFarm'); | ||
const worker = require('./utils/promisify')(require('./worker.js')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it normal that |
||
const Path = require('path'); | ||
const Bundle = require('./Bundle'); | ||
const {FSWatcher} = require('chokidar'); | ||
|
@@ -262,19 +261,21 @@ class Bundler extends EventEmitter { | |
try { | ||
return await this.resolveAsset(dep.name, asset.name); | ||
} catch (err) { | ||
if (err.message.indexOf(`Cannot find module '${dep.name}'`) === 0) { | ||
err.message = `Cannot resolve dependency '${dep.name}'`; | ||
let thrown = err; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes no-ex-assign |
||
|
||
if (thrown.message.indexOf(`Cannot find module '${dep.name}'`) === 0) { | ||
thrown.message = `Cannot resolve dependency '${dep.name}'`; | ||
|
||
// Generate a code frame where the dependency was used | ||
if (dep.loc) { | ||
await asset.loadIfNeeded(); | ||
err.loc = dep.loc; | ||
err = asset.generateErrorMessage(err); | ||
thrown.loc = dep.loc; | ||
thrown = asset.generateErrorMessage(thrown); | ||
} | ||
|
||
err.fileName = asset.name; | ||
thrown.fileName = asset.name; | ||
} | ||
throw err; | ||
throw thrown; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ class FSCache { | |
await fs.writeFile(this.getCacheFile(filename), JSON.stringify(data)); | ||
this.invalidated.delete(filename); | ||
} catch (err) { | ||
// eslint-disable-next-line no-console | ||
console.error('Error writing to cache', err); | ||
} | ||
} | ||
|
@@ -70,7 +71,9 @@ class FSCache { | |
try { | ||
await fs.unlink(this.getCacheFile(filename)); | ||
this.invalidated.delete(filename); | ||
} catch (err) {} | ||
} catch (err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did ESLint complain about this? Also, never really a good idea to have anything fail silently, imo. But that's another discussion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's why I added a comment: I did not want to deactivate this rule |
||
// Fail silently | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
const Asset = require('../Asset'); | ||
const postcss = require('postcss'); | ||
const valueParser = require('postcss-value-parser'); | ||
const path = require('path'); | ||
const md5 = require('../utils/md5'); | ||
const postcssTransform = require('../transforms/postcss'); | ||
const CssSyntaxError = require('postcss/lib/css-syntax-error'); | ||
|
||
const URL_RE = /url\s*\(\"?(?![a-z]+:)/; | ||
const URL_RE = /url\s*\("?(?![a-z]+:)/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. ESLint seems to have removed some bit of regex. Again, ignore if I'm wrong. 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. The |
||
const IMPORT_RE = /@import/; | ||
const PROTOCOL_RE = /^[a-z]+:/; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to specify the context used by files in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll do it :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, and I also replaced one |
||
"extends": "../../.eslintrc.json", | ||
"env": { | ||
"browser": true | ||
}, | ||
"rules": { | ||
"no-global-assign": [1] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ function getBundleURL() { | |
try { | ||
throw new Error; | ||
} catch (err) { | ||
var matches = ('' + err.stack).match(/(https?|file|ftp):\/\/[^\)\n]+/g); | ||
var matches = ('' + err.stack).match(/(https?|file|ftp):\/\/[^)\n]+/g); | ||
if (matches) { | ||
return getBaseURL(matches[0]); | ||
} | ||
|
@@ -22,7 +22,7 @@ function getBundleURL() { | |
} | ||
|
||
function getBaseURL(url) { | ||
return ('' + url).replace(/^((?:https?|file|ftp):\/\/.+)\/[^\/]+$/, '$1') + '/'; | ||
return ('' + url).replace(/^((?:https?|file|ftp):\/\/.+)\/[^/]+$/, '$1') + '/'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. ESLint seems to have removed some bit of regex. Again, ignore if I'm wrong. 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. The |
||
} | ||
|
||
exports.getBundleURL = getBundleURLCached; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,6 @@ function reloadCSS() { | |
|
||
cssTimeout = null; | ||
}, 50); | ||
}; | ||
} | ||
|
||
module.exports = reloadCSS; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ class Packager { | |
|
||
async start() {} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this particular one needed? I don't see any unused vars. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly: I prefered not to remove it, because it seems to be useful for documentation |
||
async addAsset(asset) { | ||
throw new Error('Must be implemented by subclasses'); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
const {AST_Node, minify} = require('uglify-js'); | ||
const {toEstree} = require('babel-to-estree'); | ||
const types = require('babel-types'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these |
||
const walk = require('babylon-walk'); | ||
|
||
module.exports = async function(asset) { | ||
await asset.parseIfNeeded(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ const isURL = require('is-url'); | |
const ANCHOR_REGEXP = /^#/; | ||
|
||
// Matches scheme (ie: tel:, mailto:, data:) | ||
const SCHEME_REGEXP = /^[a-z]*\:/i; | ||
const SCHEME_REGEXP = /^[a-z]*:/i; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. ESLint seems to have removed some bit of regex. Again, ignore if I'm wrong. 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. The |
||
|
||
module.exports = function(url) { | ||
return isURL(url) || ANCHOR_REGEXP.test(url) || SCHEME_REGEXP.test(url); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
const template = require('babel-template'); | ||
const Path = require('path'); | ||
const types = require('babel-types'); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
require('v8-compile-cache'); | ||
const fs = require('./utils/fs'); | ||
const Parser = require('./Parser'); | ||
const babel = require('./transforms/babel'); | ||
|
||
let parser; | ||
|
||
function emit(event, ...args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function does not seem to be called |
||
process.send({event, args}); | ||
} | ||
|
||
exports.init = function(options, callback) { | ||
parser = new Parser(options || {}); | ||
callback(); | ||
|
@@ -25,11 +19,13 @@ exports.run = async function(path, pkg, options, callback) { | |
hash: asset.hash | ||
}); | ||
} catch (err) { | ||
let returned = err; | ||
|
||
if (asset) { | ||
err = asset.generateErrorMessage(err); | ||
returned = asset.generateErrorMessage(returned); | ||
} | ||
|
||
err.fileName = path; | ||
callback(err); | ||
returned.fileName = path; | ||
callback(returned); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed to specify that in this repository, the environment is different (it is using mocha) |
||
"extends": "../.eslintrc.json", | ||
"env": { | ||
"mocha": true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the master configuration file