Skip to content
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

Merged
merged 18 commits into from
Dec 21, 2017

Conversation

ghusse
Copy link
Contributor

@ghusse ghusse commented Dec 9, 2017

Adds ESLint to the build process:

  • Adds .eslintrc.json files to configure ESLint at different levels
  • Fixes some bugs / warnings revealed by ESLint
  • Adds inline comments for disabling ESLint in some situations
  • Launches ESLint in Travis CI
  • Launches ESLint in the precommit hook

For 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 named import. 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

Copy link
Contributor Author

@ghusse ghusse left a 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes no-ex-assign

@@ -1,7 +1,5 @@
const {AST_Node, minify} = require('uglify-js');
const {toEstree} = require('babel-to-estree');
const types = require('babel-types');
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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'));
Copy link
Contributor Author

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?

Copy link
Contributor

@yeskunall yeskunall left a 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(/[?#].*$/, '');
Copy link
Contributor

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? 🤔

Copy link
Contributor

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:
`` ?#

Copy link
Contributor

@yeskunall yeskunall Dec 10, 2017

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!

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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]+:)/;
Copy link
Contributor

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. 😅

Copy link
Contributor

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') + '/';
Copy link
Contributor

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. 😅

Copy link
Contributor

@brandon93s brandon93s Dec 10, 2017

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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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. 😅

Copy link
Contributor

@brandon93s brandon93s Dec 10, 2017

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 😅

@yeskunall
Copy link
Contributor

@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. 💖

@itsMapleLeaf
Copy link
Contributor

I believe those are in places where the escape is unnecessary, so it should be fine 🙂

@yeskunall
Copy link
Contributor

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 */
Copy link
Contributor

@brandon93s brandon93s Dec 10, 2017

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.

Copy link
Contributor Author

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

@yeskunall
Copy link
Contributor

yeskunall commented Dec 10, 2017

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 /* eslint-enable no-console */ (or something along the lines) during my initial review, but forgot to mention them. I think that for all purposes, this should be safe to turn off, or at the very list, switched to only warn the user.

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",
Copy link
Contributor

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?

Copy link
Contributor

@yeskunall yeskunall Dec 10, 2017

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.

Copy link
Contributor Author

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

@ghusse
Copy link
Contributor Author

ghusse commented Dec 10, 2017

I pushed new modifications to this PR. Let me know if there are other changes you'd like to see.

@brandon93s
Copy link
Contributor

Are all of the sub eslintrc necessary? Can they be consolidated into the parent by promoting the rules? I see they're extending one another, but would want to reduce as much maintenance overhead as possible.

@ghusse
Copy link
Contributor Author

ghusse commented Dec 11, 2017

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.

Copy link
Contributor Author

@ghusse ghusse left a 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 @@
{
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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)

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 @@
{
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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

@ghusse
Copy link
Contributor Author

ghusse commented Dec 11, 2017

Did I introduce regressions? It seems that this build is pretty new, are the test passing on master?

@ghusse
Copy link
Contributor Author

ghusse commented Dec 11, 2017

Ok, I need to investigate why tests are failing. It seems that this PR introduces a regression somewhere, as test are passing on master.

@ghusse
Copy link
Contributor Author

ghusse commented Dec 11, 2017

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.

@ghusse
Copy link
Contributor Author

ghusse commented Dec 11, 2017

Ok, all tests are passing, and all the warnings from master are fixed in this branch.

@@ -0,0 +1,9 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the following:

"parserOptions": {
  "ecmaVersion": 5
}

This will protect against future regressions (see #169, #227) since these aren't currently processed by Babel.

Copy link
Contributor Author

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 :-)

Copy link
Contributor Author

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.

@ghusse
Copy link
Contributor Author

ghusse commented Dec 12, 2017

Anything else to change on this PR?

@yeskunall
Copy link
Contributor

At this point, you should ping one of the members @ghusse 😁

@davidnagli
Copy link
Contributor

@yeskunall No need to ping us, we’re always watching 👀

@yeskunall
Copy link
Contributor

@davidnagli

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>
Copy link
Contributor

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?

Copy link
Contributor

@yeskunall yeskunall Dec 12, 2017

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

@ghusse
Copy link
Contributor Author

ghusse commented Dec 13, 2017

@davidnagli @yeskunall Anything I can do for this PR to be merged?

@yeskunall
Copy link
Contributor

I don't have push access @ghusse 😟 (at this point you should really ping someone who has the access)

@ghusse
Copy link
Contributor Author

ghusse commented Dec 13, 2017

ping @brandon93s ?

@brandon93s
Copy link
Contributor

Looks ready to go to me.

@devongovett
Copy link
Member

Looks good. can you fix the conflicts?

@ghusse
Copy link
Contributor Author

ghusse commented Dec 20, 2017

Conflicts solved (I had to fix other errors introduced by recent commits)

@yeskunall
Copy link
Contributor

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. 😄

@devongovett devongovett merged commit 434b86c into parcel-bundler:master Dec 21, 2017
@devongovett
Copy link
Member

Awesome, thanks for doing this!

No need to squash btw, I'll do that on merge.

devongovett pushed a commit that referenced this pull request Oct 15, 2018
* 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
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants