-
-
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
Conversation
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.
I added inline comments to explain modifications in this PR or ask questions about the current code.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes no-ex-assign
src/transforms/uglify.js
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Are these require
statements required for babel? I removed them because the variables are not used.
|
||
let parser; | ||
|
||
function emit(event, ...args) { |
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.
This function does not seem to be called
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is it normal that worker
was not used?
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.
Wow, that looks like some work you put in there @ghusse 😁 thanks for getting this in so quickly. I've made some comments based on what I've noticed. Might not be right in all the places, but these are just my 2 cents.
src/Asset.js
Outdated
@@ -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 comment
The 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 \
, which could potentially change the result of resolved
. Wouldn't that mean that it would now also remove ?
and #
from the path? 🤔
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.
In this case, they are the same.
[\?#]
=> match any item in the list:
- literal ?
- literal #
[?#]
=> match any item in the list:
`` ?#
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yep: ESLint was complaining about unecessary escapes.
@@ -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 comment
The 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 comment
The 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
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. The \
was an unnecessary character escape. Same functionality.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. The \
was an unnecessary character escape. Same functionality.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
asset
is unused. Guessing it was left to be self-documenting since this requires implementation by extending classes.
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.
Exactly: I prefered not to remove it, because it seems to be useful for documentation
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. The \
was an unnecessary character escape. Same functionality.
{ | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 8 |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, babel seem used everywhere in parcel. It allows to use async
/await
for instance, which is not supported by Node 6 and si part of ecmaScript 2017 or 8. That's why this version here is needed.
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.
Yup, you're right. The whole codebase is later transpiled using Babel. This should be okay. Thanks for the clarification 😅
@ghusse noticed a trend where ESLint just removed some parts of the regex. I've mentioned that in quite a few places in my review (sorry about that), but other than that, this looks really good. Appreciate it. 💖 |
I believe those are in places where the escape is unnecessary, so it should be fine 🙂 |
Yup, that's what ESLint says. But I pushed some code once that removed those escapes without checking and my tests started failing. Admittedly, I didn't know what I was doing with regex then, and I still don't. 😅 Thanks tho @kingdaro 💖 |
bin/cli.js
Outdated
@@ -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 comment
The 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 eslintrc
? Several files required this disable.
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.
Ok, I'll change that
So the general consensus is that I'm just bad at regex. Feel free to ignore all comments I made about the regex issues. However, @ghusse I did notice a lot of EDIT: as @brandon93s points out, it should be safe to turn it off. |
package.json
Outdated
"*.{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 comment
The reason will be displayed to describe this comment to others. Learn more.
Running eslint
on md
files?
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.
Yeah, it should instead do an npm run lint
before lint-staged
in the precommit hook.
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.
woops. Thanks. I'll change that
I pushed new modifications to this PR. Let me know if there are other changes you'd like to see. |
Are all of the sub |
I created a sub-config file everywhere the context changed, or different rules have to be applied. That's the way eslint is handling these cases. I can comment every file to explain why I created it if you want. |
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.
I commented every configuration file to explain why I created it
@@ -0,0 +1,10 @@ | |||
{ |
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
@@ -0,0 +1,6 @@ | |||
{ |
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.
I created this one in the bin
directory to deactivate the no-console
rule just here.
I propose not to deactivate it everywhere, because usage of console.log
can be signs of forgotten test code. But if you prefer I can move it to the general configuration (but deactivate it in tests)
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.
It was a great time with you
@@ -0,0 +1,9 @@ | |||
{ |
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.
I needed to specify the context used by files in builtins
, as a browser context. Some files are using features specific to browsers (such as WebSocket
for what I remember)
@@ -0,0 +1,6 @@ | |||
{ |
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.
Needed to specify that in this repository, the environment is different (it is using mocha)
@@ -0,0 +1,10 @@ | |||
{ |
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.
Integration test code is using browser-specific features and special functions output
and import
that are used in different files. This is not the case in the rest of the code.
@@ -0,0 +1,9 @@ | |||
{ |
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.
This directory contains code that tests the ES6 syntax for importing and exporting code. ESLint needs a specific configuration to support this syntax, and we cannot use inline-configuration comments for this.
@@ -0,0 +1,6 @@ | |||
{ |
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.
Needed to support the parsing of ES6 import/export syntax
@@ -0,0 +1,6 @@ | |||
{ |
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.
Needed to support the parsing of ES6 import/export syntax
@@ -0,0 +1,6 @@ | |||
{ |
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.
Needed to support the parsing of ES6 import/export syntax
Did I introduce regressions? It seems that this build is pretty new, are the test passing on master? |
Ok, I need to investigate why tests are failing. It seems that this PR introduces a regression somewhere, as test are passing on master. |
Ok, indeed, I introduced regressions with my fixes on prelude.js. I just pushed a version that both work, and statisfies ESLint rule of not creating a function inside a if statement. |
Ok, all tests are passing, and all the warnings from master are fixed in this branch. |
@@ -0,0 +1,9 @@ | |||
{ |
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.
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.
Ok, I'll do it :-)
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.
Done, and I also replaced one const
and one let
by var
in src/builtins/index.js
.
Anything else to change on this PR? |
At this point, you should ping one of the members @ghusse 😁 |
@yeskunall No need to ping us, we’re always watching 👀 |
CONTRIBUTING.md
Outdated
<a href="https://opencollective.com/parcel/sponsor/9/website" target="_blank"><img src="https://opencollective.com/parcel/sponsor/9/avatar.svg"></a> |
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.
Did I miss something, or are these exactly the same?
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.
EOL/EOF mismatch between OSes because of git? Sure looks like it.
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.
Sh******
Thanks, I'll change that
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.
I checked the file, it seems that this file is now encoded using LF. I suppose that it was not the case on master. Do you want me to revert changes on that file?
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.
I don’t think it makes any difference
@davidnagli @yeskunall Anything I can do for this PR to be merged? |
I don't have push access @ghusse 😟 (at this point you should really ping someone who has the access) |
ping @brandon93s ? |
Looks ready to go to me. |
Looks good. can you fix the conflicts? |
Conflicts solved (I had to fix other errors introduced by recent commits) |
Hey @ghusse this is killer! Thanks for not giving up on this PR. Do you also mind squashing your commits? It's just a suggestion. 😄 |
Awesome, thanks for doing this! No need to squash btw, I'll do that on merge. |
* 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
* 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
Adds ESLint to the build process:
.eslintrc.json
files to configure ESLint at different levelsFor some files in integration tests, I had to disable ESLint because the syntax is a mix of the
import
export
from ES6, and the support of a special function namedimport
. I suppose that this is revealing an issue with the current syntax supported by parcel, but in the meantime, I just ignored these files as they cannot be parsed by ESLint.For the moment, only the recommended rules from ESLint have been applied. Feel free to propose customizations.
Closes #173