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
remove gitDir config option #327
Conversation
Codecov Report
@@ Coverage Diff @@
## master #327 +/- ##
==========================================
+ Coverage 97.15% 97.28% +0.12%
==========================================
Files 10 10
Lines 176 184 +8
Branches 26 25 -1
==========================================
+ Hits 171 179 +8
Misses 5 5
Continue to review full report at Codecov.
|
Amazing work @camacho! Does tests cover all edge cases? I didn't see any tests where |
Those cases should be covered by the spec changes. I adjusted the old tests to account for a different |
@@ -77,8 +88,21 @@ describe('generateTasks', () => { | |||
}) | |||
}) | |||
|
|||
it('should not match non-children files', () => { | |||
const relPath = path.resolve(path.join(process.cwd(), '..')) | |||
resolveGitDir.mockReturnValueOnce(relPath) |
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.
@okonet check for filtering out files that aren't in the cwd
but show up because gitDir
is diff
it('should pass cwd to execa if gitDir option is set for non-npm tasks', async () => { | ||
const res = runScript(['test', 'git add'], ['test.js'], scripts, { gitDir: '../' }) | ||
it('should pass cwd to execa if gitDir is different than process.cwd for non-npm tasks', async () => { | ||
resolveGitDir.mockReturnValue('../') |
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.
@okonet check for proper execa
cwd if gitDir
is diff than process.cwd
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.
Looks good overall, only minor changes required.
src/generateTasks.js
Outdated
const fileList = files | ||
// Only worry about children of the CWD | ||
.filter(file => file.startsWith(cwd)) |
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.
Let's use path-is-inside
here. From the readme:
It turns out this question isn't trivial to answer using Node's built-in path APIs. A naive
indexOf
-based solution will fail sometimes on Windows, which is case-insensitive (see e.g. isaacs/npm#4214).
test/resolveGitDir.spec.js
Outdated
@@ -13,14 +12,4 @@ describe('resolveGitDir', () => { | |||
expect(resolveGitDir('.')).toEqual(expected) |
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.
resolveGitDir
no longer accepts an argument. Please remove the parameter '.'
in the function invocation.
@sudo-suhas updated based on feedback |
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.
Thanks @camacho!
@okonet Do you think it would be a good idea to publish this with the |
@sudo-suhas why not do just breaking change? I feel like I'm not having enough time to batch changes into bigger releases and I don't want to postpone on new features from PRs. |
@camacho could you please resolve the conflicts and update the branch? Also I don't quite get your comments on tests: do you mean our tests aren't exhausting or what exactly? |
@okonet sorry for not being more clear. The tests seem extensive enough. I was trying to highlight the places in the code where we test the gitDir being different than the process cwd. As far as I can tell, all cases are covered, but I am happy to add more tests if you have any cases in mind that are uncovered. conflicts resolved |
@okonet Breaking changes is a good idea. That will suffice. |
@camacho one question that struck me before the merge: how this PR behaves with old configs that has the option? Will it output the deprecation message? |
@okonet Good catch! I think it will print the |
I've tested it and it displays a generic message right now:
which is confusing. Let's add a proper deprecation message, please. You'll need to add See https://github.com/facebook/jest/tree/master/packages/jest-validate for more information. |
@camacho here is the patch you need to apply: diff --git a/src/getConfig.js b/src/getConfig.js
index dc93440..fe8e684 100644
--- a/src/getConfig.js
+++ b/src/getConfig.js
@@ -30,6 +30,14 @@ const defaultConfig = {
verbose: false
}
+const deprecatedConfig = {
+ gitDir: config => ` Option ${chalk.bold('gitDir')} was removed.
+
+ lint-staged now automatically resolves '.git' directory.
+
+ Please remove ${chalk.bold('gitDir')} from your configuration.`
+}
+
/**
* Check if the config is "simple" i.e. doesn't contains any of full config keys
*
@@ -121,6 +129,7 @@ function validateConfig(config) {
const validation = validate(config, {
exampleConfig,
+ deprecatedConfig,
unknown: unknownValidationReporter,
comment:
'Please refer to https://github.com/okonet/lint-staged#configuration for more information...' |
Requested changes pushed |
@camacho could you please add a snapshot test for this? |
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.
Only minor changes. Thank you @camacho for addressing all the feedback. Hopefully this is the last one 😉
test/getConfig.spec.js
Outdated
@@ -211,6 +211,17 @@ describe('validateConfig', () => { | |||
expect(console.printHistory()).toMatchSnapshot() | |||
}) | |||
|
|||
it('should not throw and should print validation warnings for old config', () => { |
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.
Can we change this test title to should print deprecation warning for gitDir option
?
test/getConfig.spec.js
Outdated
@@ -211,6 +211,17 @@ describe('validateConfig', () => { | |||
expect(console.printHistory()).toMatchSnapshot() | |||
}) | |||
|
|||
it('should not throw and should print validation warnings for old config', () => { | |||
const invalidMixedConfig = { |
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.
Rename variable to configWithDeprecatedOpt
please.
" | ||
WARN ● Deprecation Warning: | ||
|
||
Option gitDir was removed. |
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.
@okonet Does the formatting for this text seem a bit odd to you?
updated |
Had to amend from master and force push master :( Lessons learned: don't merge breaking changes from the bed on the iPad 🤦♂️ |
Thanks again for your work! |
Happy to contribute @okonet |
* Remove `gitDir` config option * Automatically resolve `.git` directory in the project Closes #271 BREAKING CHANGE: `gitDir` option deprecated and will be ignored
Good thing you caught it early. |
close #271