-
Notifications
You must be signed in to change notification settings - Fork 141
Use getConfigForFile to handle configurations #1068
Conversation
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. |
Ironically enough this is a return to using this API, as it was originally written for |
65fd503
to
a0c91ea
Compare
const tempFixturePath = await copyFileToTempDir(fixtureFile) | ||
const tempDir = Path.dirname(tempFixturePath) | ||
const filepath = Path.join(tempDir, 'good.js') | ||
const filePath = await copyFileToTempDir(fixtureFile) |
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 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 withtempFixture
or even reverting to the oldtempFixturePath
.
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.
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.
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.
Do you do not think it is signficant the the path points to a fixture vs any other random 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.
All of the paths point to a fixture and not "any other random file", so it would be quite significant if it didn't.
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 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) { |
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 what cases would would response
have a falsey value here?
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 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 false
y.
return configFile | ||
export function getConfigForFile(eslint, filePath) { | ||
const cli = new eslint.CLIEngine() | ||
try { |
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 this a dangerous function call that could throw? No use of try
in api docs.
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.
If it can't find a configuration at all it throw
s an Error
(hence the comment).
a0c91ea
to
3cb0d85
Compare
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. |
9809c39
to
9c6a0da
Compare
9c6a0da
to
0aa336d
Compare
0aa336d
to
5928dc8
Compare
6b97ed4
to
03685db
Compare
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]>
03685db
to
fe8adf0
Compare
For the record, this was rebased. A backup branch is available here: |
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: |
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.
LGTM
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.
Awesome!
It is not as breaking as I thought. It works without any issues
🎉 This PR is included in version 8.6.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.