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

Enable ESLint #415

Merged
merged 1 commit into from
Dec 7, 2019
Merged

Enable ESLint #415

merged 1 commit into from
Dec 7, 2019

Conversation

adroitwhiz
Copy link
Contributor

This PR enables ESLint and lints the codebase with it.

The linting rules used are the "recommended" settings for ESLint, with the following exceptions:

  • Semicolons are required. By default, ESLint doesn't take a position on the explicit semicolons/automatic semicolon insertion debate, and since this codebase uses semicolons, ESLint should enforce that usage consistently.
  • Unused variables are allowed, owing to the number at which they are currently present in the codebase.

The vast majority of fixes fall into the following categories:

There are a few changes that may affect code behavior:

  • In path.js, a global variable leak has been fixed (the variable v was missing a var statement and hence leaking into global scope)
  • In webgl.js, one use of the undefined max function (I confirmed with a debugger that it's not defined in that scope) was replaced with Math.max
  • In two.js line 1335, a loop that changed the value of i given by 'forEach' now uses the j variable--not sure if that changes anything
  • In getAnchorsFromArcData (two.js line 2125), the unused 'matrix' variable declaration has been removed
  • In Two.Utils.Events.trigger (two.js line 2321), ev has been changed to event. ev was not defined.

@jonobr1
Copy link
Owner

jonobr1 commented Dec 5, 2019

This is awesome, thanks! I'll check two.js line 1335 to make sure that changing i to j is not a problem.

.eslintrc.json Outdated
},
"overrides": [
{
"files": ["utils/**", "tests/**"],
Copy link
Owner

Choose a reason for hiding this comment

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

Just to confirm it lines everything that's not in the overrides?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The overrides mean "apply these linting rules to only these specific files".

I'm using it here so it knows that "utils" and "tests" are running in Node, and "tests" has some QUnit-related global variables (ESLint will otherwise complain about accessing undeclared global variables).

@adroitwhiz
Copy link
Contributor Author

Since QUnit runs in the browser, I've removed it from the "env": {"node": true} override.

@jonobr1 jonobr1 merged commit eacba1a into jonobr1:dev Dec 7, 2019
@jonobr1
Copy link
Owner

jonobr1 commented Dec 7, 2019

I'll add linting as a step in the build script 🙇

@jonobr1
Copy link
Owner

jonobr1 commented Dec 7, 2019

This has been merged, but actually I'm getting errors when trying to lint. "ESLint couldn't find the config "airbnb-base" to extend from. Please check that the name of the config is correct."

Is that something you have npm installed globally?

@adroitwhiz
Copy link
Contributor Author

adroitwhiz commented Dec 7, 2019

I'm not sure--there's nothing Airbnb-related in the .eslintrc.json, and no Airbnb-related dependencies that appear in ESLint's dependencies.

Are you running the version of eslint this project depends on with npm run lint or ./node_modules/.bin/eslint, or are you running a globally-installed eslint? The latter may do weird things.

@jonobr1
Copy link
Owner

jonobr1 commented Dec 7, 2019

I deleted my node_modules folder, ran npm install, and then npm run lint. I can pull a full error log.

@adroitwhiz
Copy link
Contributor Author

An error log would be helpful; I can't seem to reproduce this on Linux or Windows.

@jonobr1
Copy link
Owner

jonobr1 commented Dec 7, 2019

It was an issue with me. I keep a /junk folder in the project to add and test other aspects of Two.js and was using webpack and rollup. In there I was referencing airbnb-base. A simple ignore of /junk in the eslintrc.json fixed that.

elShiaLabeouf pushed a commit to elShiaLabeouf/two.js that referenced this pull request Dec 17, 2021
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.

None yet

2 participants