Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Make Linter Eslint: Fix File to use the same ESLint as when linting #307

Merged
merged 14 commits into from
Nov 30, 2015

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Nov 19, 2015

Moves the execution of eslint --fix to the worker, and uses the same eslint resolution as linting.

Fixes #300

global: atom.config.get('linter-eslint.useGlobalEslint'),
nodePath: atom.config.get('linter-eslint.globalNodePath'),
}
const eslintDir = findEslintDir(params)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would highly recommend that we do not do this in the main process, the sync file system operations and sync execution is gonna make the editor jam for the user

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'll have to study up on how to use a worker. Any tips?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's how you can give a job to worker, the request method will return a promise that will resolve when worker replies, You can either return a promise or a value from the worker, like it's done here, here and here

@IanVS
Copy link
Member Author

IanVS commented Nov 20, 2015

Hm, not sure why CI is failing here. Please give this a thorough review. It seems to work when I test locally, but without specs it's hard to know for sure that I haven't borked anything up.

@Arcanemagus
Copy link
Member

CI is failing currently since apm test has no specs to test so it always fails. I'm working on those right now 😉.

}

const modulesPath = find(params.fileDir, 'node_modules')
const eslintignoreDir = Path.dirname(find(params.fileDir, '.eslintignore'))
let eslintNewPath = null
if (modulesPath) {
process.env.NODE_PATH = modulesPath
} else process.env.NODE_PATH = ''
require('module').Module._initPaths()
Copy link
Member Author

Choose a reason for hiding this comment

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

Question

What does this line do?

Copy link
Contributor

Choose a reason for hiding this comment

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

process.env.NODE_PATH change is not recognized by the node module loader, this line makes sure it does

@IanVS
Copy link
Member Author

IanVS commented Nov 29, 2015

@steelbrain & @Arcanemagus, sorry for the rather large PR here. This does several things:

  • Extracts shared/reusable logic into helper functions
  • Adds unit tests for those helper functions
  • Reorganizes the test fixture files to be more isolated
  • Fixes a few bugs I came across while testing
  • Finally, fixes Run fix command in worker #300 and improves the fix behavior by alerting the user as to the results.

Please let me know if you'd like to see more tests, or if this needs to be broken up.

}

if (this.worker === null) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

No semi-colons please 😛

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a hard habit to break. :) We should turn on semi: never. In fact, I'll do that now and fix any errors. (Will be a good test of the --fix functionality too!)

Copy link
Member

Choose a reason for hiding this comment

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

Personally I like having them in there, but can live without them. Just as long as the files are consistent 😛.

@Arcanemagus
Copy link
Member

LGTM other than the null fix worker noted above.

Ian VanSchooten and others added 13 commits November 30, 2015 15:55
Fixes #300

This allows the `Linter Eslint: Fix file` command to use the same ESLint
which is being used for linting the files, avoiding problems when plugins
or shared configs are used.

This also puts the execution of ESLint for error fixing onto the worker,
which will free up the UI from being blocked.  It also adds messages to
indicate the success or partial success of the operation.  ESLint will
report a 0 exit code only if all linting errors are removed.  Otherwise,
if any linting errors remain, it will exit with a 1, in which case a
warning will be displayed to indicate the operation is complete, but there
are still errors.

Also, this commit abstracts more methods into a helper, for reusability and testability.
Without this change, when an absolute path is provided, the leading slash
is used as a separator and the first element of the chunks array is an 
empty string.  

With this change, the first element is replaced with a path separator,
so that the reconstructed currentDirectory is an absolute path, as desired.
Instead of writing each subdirectory as a separate argument (which wasn’t
being done correctly in the tests anyway), expect a single argument, 
`path`, which is a UNIX-style path.
let prefixPath = null

function findEslintDir(params) {
const eslintPathLocal = Path.join(FS.realpathSync(Path.join(__dirname, '..')), 'node_modules', 'eslint')
Copy link
Contributor

Choose a reason for hiding this comment

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

Because the value of this doesn't change and syscalls are expensive, can we move this in upper scope please?

Bringing it out into the function’s closure will avoid repeated syscalls.
IanVS added a commit that referenced this pull request Nov 30, 2015
Make `Linter Eslint: Fix File` use the same ESLint as when linting
@IanVS IanVS merged commit 73672bf into master Nov 30, 2015
@Arcanemagus Arcanemagus deleted the issue300 branch November 30, 2015 21:30
@steelbrain
Copy link
Contributor

👏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants