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

Use getConfigForFile to handle configurations #1068

Merged
merged 1 commit into from
Mar 14, 2021

Conversation

Arcanemagus
Copy link
Member

@Arcanemagus Arcanemagus commented Jan 7, 2018

Move to using CLIEngine#getConfigForFile to handle determination of the configuration for a file instead of our attempts to replicate this behavior.

Note that if a user has a configuration in their home directory, and nowhere more specific for a file, previously we were counting this as "no configuration" for the purposes of the "Disable when no config"
option. After this change we are doing the same thing ESLint does: Using this configuration. If this isn't what a user desires, they should move away from a "global config".

Note: This function was introduced in ESLint v0.9.0, so this change will make us incompatible with versions older than that, however I believe we make more assumptions that require at least ESLint v1 elsewhere in the code so this isn't a huge deal.

@Arcanemagus Arcanemagus self-assigned this Jan 7, 2018
@Arcanemagus Arcanemagus requested a review from IanVS January 7, 2018 11:10
@Arcanemagus
Copy link
Member Author

I honestly expected this to be a larger change, while I was fixing the specs up I cleaned out several folders that were no longer used.

@Arcanemagus
Copy link
Member Author

Ironically enough this is a return to using this API, as it was originally written for linter-eslint after a request by @jfaissolle in eslint/eslint#1309.

@Arcanemagus Arcanemagus force-pushed the arcanemagus/getConfigForFile branch 2 times, most recently from 65fd503 to a0c91ea Compare January 17, 2018 17:19
const tempFixturePath = await copyFileToTempDir(fixtureFile)
const tempDir = Path.dirname(tempFixturePath)
const filepath = Path.join(tempDir, 'good.js')
const filePath = await copyFileToTempDir(fixtureFile)
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 generally very much in favor of trying to shorten variable names to reduce noise, but this seems to end up way too vague.

  • The name filePath seems to denote a generic file or directory, this is a very specific file.
  • I think both "file" and "path" are fairly strongly implied by the usage and context of this variable. It takes almost 0 mental overhead to infer this is a filepath string, no matter what name we use.
  • With that in mind, my preference here would actually just be fixture. But I'm certainly fine also with tempFixture or even reverting to the old tempFixturePath.

Copy link
Member Author

Choose a reason for hiding this comment

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

tempFixturePath isn't the "old" name. If you look at what the code was doing previously it was getting the dirname of the tempFixturePath and then re-appending good.js onto it into filepath for some reason. I just cut out that busywork and am storing it directly into filePath.

As for filePath vs tempFixturePath, I'm not entirely sure what filePath would refer to other than a specific file's path? The idea with the current naming is that the code would look the same whether the file was temporary or not so I don't really like the idea of having temp in the name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you do not think it is signficant the the path points to a fixture vs any other random file?

Copy link
Member Author

Choose a reason for hiding this comment

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

All of the paths point to a fixture and not "any other random file", so it would be quite significant if it didn't.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok fair enough. I'm still not loving it. Doesn't seem to mesh well with the way I think, but after hearing your arguments I'm down to about 1/10 on the GaS scale.

src/main.js Outdated
@@ -359,7 +332,7 @@ module.exports = {
filePath,
projectPath
})
if (!isSave) {
if (!isSave && response) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In what cases would would response have a falsey value here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that I was only looking at the return here and somehow ignored the emit right above it. I don't think there is a case where that could be falsey.

return configFile
export function getConfigForFile(eslint, filePath) {
const cli = new eslint.CLIEngine()
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a dangerous function call that could throw? No use of try in api docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

If it can't find a configuration at all it throws an Error (hence the comment).

@Arcanemagus Arcanemagus force-pushed the arcanemagus/getConfigForFile branch from a0c91ea to 3cb0d85 Compare January 17, 2018 19:59
@Arcanemagus
Copy link
Member Author

Note that if a user has a configuration in their home directory, and nowhere more specific for a file, previously we were counting this as "no configuration" for the purposes of the "Disable when no config"
option. After this change we are doing the same thing ESLint does: Using this configuration. If this isn't what a user desires, they should move away from a "global config".

I really want to draw attention to this as it's a change in behavior from what we currently do. I think it's a good idea since it brings us perfectly in line with how ESLint works, but I want to make sure people are thinking about it.

@Arcanemagus Arcanemagus force-pushed the arcanemagus/getConfigForFile branch 7 times, most recently from 9809c39 to 9c6a0da Compare January 23, 2018 17:33
@Arcanemagus Arcanemagus force-pushed the arcanemagus/getConfigForFile branch from 9c6a0da to 0aa336d Compare January 29, 2018 19:27
@Arcanemagus Arcanemagus force-pushed the arcanemagus/getConfigForFile branch from 0aa336d to 5928dc8 Compare March 2, 2018 21:22
@aminya aminya force-pushed the arcanemagus/getConfigForFile branch from 6b97ed4 to 03685db Compare March 14, 2021 06:52
Move to using `CLIEngine#getConfigForFile` to handle determination of
the configuration for a file instead of our attempts to replicate this
behavior.

Note that if a user has a configuration in their home directory, and
nowhere more specific for a file, previously we were counting this as
"no configuration" for the purposes of the "Disable when no config"
option. After this change we are doing the same thing ESLint does: Using
this configuration. If this isn't what a user desires, they should move
away from a "global config".

Co-Authored-By: Landon Abney <[email protected]>
@aminya aminya force-pushed the arcanemagus/getConfigForFile branch from 03685db to fe8adf0 Compare March 14, 2021 06:54
@aminya
Copy link
Member

aminya commented Mar 14, 2021

For the record, this was rebased. A backup branch is available here:
https://github.com/AtomLinter/linter-eslint/tree/getConfigForFile-Backup

@aminya aminya requested review from aminya and UziTech March 14, 2021 06:56
@aminya
Copy link
Member

aminya commented Mar 14, 2021

I am going to use this branch for a while to see if I see an issue with it. After a week or so, we can merge it.

This PR will help us with the following PR:
#1360

Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@aminya aminya left a comment

Choose a reason for hiding this comment

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

Awesome!

It is not as breaking as I thought. It works without any issues

@aminya aminya merged commit 5c79196 into master Mar 14, 2021
@aminya aminya deleted the arcanemagus/getConfigForFile branch March 14, 2021 07:43
@github-actions
Copy link

🎉 This PR is included in version 8.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants