-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
Respect tslint configs hierarchical order #214
Respect tslint configs hierarchical order #214
Conversation
Sorry - I see what you mean! I've left some comments |
src/ApiIncrementalChecker.ts
Outdated
@@ -90,7 +117,7 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface { | |||
} | |||
|
|||
public hasLinter(): boolean { | |||
return !!this.linterConfig; | |||
return true; |
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.
This looks incorrect; not everyone wants to use tslint. Could you amend this please?
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.
fixed
src/ApiIncrementalChecker.ts
Outdated
linter.lint( | ||
updatedFile, | ||
undefined!, | ||
this.linterConfig || this.getLinterConfig(updatedFile) |
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 you talk me through this line please? What is this.linterConfig
in this context? What would cause it to be false-y
/ when would you expect to call this.getLinterConfig(updatedFile)
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 tried to be more explicit this time around, but still: this.linterConfig
- is a TSLint config, which is defined by path, provided by user in webpack config. Conversely, when user provides true
instead of config-file path, this.linterConfig
should be undefined
, instead, it will be calculated inside this.getLinterConfig
Suppose I have a project with three folders
content of
content of
So with such a configuration I say that I want to use |
Cool - could you take a look at my review comments please? |
yeah, working on it) |
/fixed |
Great - thanks! Could you write a test please? Integration makes the most sense I think |
will do |
/test done |
Could you catch up your fork with the changes in master please? We've just pushed out a new version which affects this fork |
…nfigs-hierarchical-order
done |
src/ApiIncrementalChecker.ts
Outdated
} | ||
this.linterConfigs[dirname] = config; | ||
} else { | ||
if (dirname === '.') { |
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 you talk me through what happens in this branch please? I've read it a bunch of times but I'm not so clear how this copes with:
- if there's only a
tslint.json
file in a particular directory of the application but not in the root - if this genuinely manages to walk up the directory tree. When
this.linterConfigs[dirname] = this.getLinterConfig(dirname);
is invoked doesn't it stick with the current directory rather than walk up to the parent? Maybe I'm misunderstanding 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.
- Do you mean "What if I want to subject to tslint some particular parts of my project by providing
tslint.config
inside, for example,src/components
folder, but not in root folder"? I assumed that it is not a legitimate case, because of the chains of imports insidesrc/components
that could lead to files from the root of project, that is why I throw an error, correct me if I'm wrong - Follow these steps:
- first file to be processed is
src/components/SomeComponent.tsx
. On the first run ofgetLinterConfig
we getconst dirname = 'src/components'
- check if
src/components/tslint.json
exists (suppose it does not) - invoke second run of
getLinterConfig('src/components')
const dirname = path.dirname('src/components') = 'src'
- check
src/tslint.json
, if it does, then OK, we've got our config, if not - then invoke third run ofgetLinterConfig('src')
- check
./tslint.json
, if it does not exist - then throw an error
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.
- Cool - that's clear thanks
I assumed that it is not a legitimate case, because of the chains of imports inside src/components that could lead to files from the root of project, that is why I throw an error, correct me if I'm wrong
I'm not sure it is an error... How does tslint itself behave in those circumstances? My assumption is that in this case we should just not lint...
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.
yeah, you're right, TSLint CLI warns No valid rules have been specified for TypeScript files
for root file, but still check inner files. Fixin' it
@@ -115,10 +145,6 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface { | |||
} | |||
|
|||
public getLints(_cancellationToken: CancellationToken) { | |||
if (!this.linterConfig) { |
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.
Does the removal of this speedy return mean that users who are not using tslint pay a performance tax as we still check for tslint.json
s?
If so I'd like to try and avoid 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.
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.
but still, I guess it never hurts to be more explicit. Fixed it
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.
So it looks like you're right - it does appear to be unnecessary. You had it right first time. 😁
Could you undo that - there's no point checking something a second time when it's already been checked.
I think then we'll be good to merge. Thanks for all your work!
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.
you got it!
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.
Actually one last thing: it looks like getLinterConfig
is repeated in src/IncrementalChecker.ts
and src/ApiIncrementalChecker.ts
.
Is there a way we could convert this into a shared function both modules could use please? You'd probably need to supply config
as a parameter for instance.
@johnnyreilly how about that? |
So I have bad news @konstantinov90. I'm a man with prejudices. Or let's call them "opinions" 😉 I don't find inheritance the most joyful thing to work with in a codebase. Whilst I completely acknowledge it could be used to solve this problem I'm afraid my innate dislike of inheritance means it troubles me deeply. If you could indulge my preferences and go for an approach that doesn't involve inheritance I would greatly appreciate it 😏 |
well then, I see two other options
What do you prefer? |
I prefer this but I don't think it need be brutal. Create a shared Sound good? |
/done |
great, thanks! |
Thanks for your work! |
Hi!
The "why" for this PR is in the README.md, please consider merging this request!