-
Notifications
You must be signed in to change notification settings - Fork 885
Conversation
Thanks for your interest in palantir/tslint, @azz! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
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 for the effort you put into this PR.
Unfortunately I still don't think this is a good idea as mentioned in the feature request.
src/runner.ts
Outdated
@@ -41,6 +41,11 @@ export interface Options { | |||
config?: string; | |||
|
|||
/** | |||
* When running with fix: true, do not write files to disk. | |||
*/ | |||
dryRun?: boolean; |
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 is only relevant for the CLI. And this doesn't make sense as CLI option
src/runner.ts
Outdated
@@ -211,6 +216,7 @@ async function doLinting( | |||
const possibleConfigAbsolutePath = options.config !== undefined ? path.resolve(options.config) : null; | |||
const linter = new Linter( | |||
{ | |||
dryRun: !!options.dryRun, |
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.
should always be false when running from CLI
const oldSource = fs.readFileSync(filePath, "utf-8"); | ||
fileNewSource = Replacement.applyFixes(oldSource, fileFixes); | ||
} | ||
fs.writeFileSync(filePath, fileNewSource); | ||
if (!this.options.dryRun && typeof fileNewSource === "string") { |
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 basically reverts #2864 when dryRun
is true. you don't want that
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.
updateProgram
is called regardless of dryRun
. Not sure what I'm missing?
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.
updateProgram reads the file from disk. With dryRun it is never updated
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.
Oh, wow. That's unfortunate. Know any way around that? I think using CompilerHost#getSourceFile
could work.
src/linter.ts
Outdated
@@ -52,6 +52,7 @@ class Linter { | |||
|
|||
private failures: RuleFailure[] = []; | |||
private fixes: RuleFailure[] = []; | |||
private fixedSources: Record<string, string> = {}; |
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.
prefer Map
#1760 (comment) and #1760 (comment) explain some of the reasons here why |
PR checklist
Overview of change:
Adds a
dryRun
option to theLinter
constructor. When set, during the fix process, no files will be written to disk. Instead, the result is returned asfixedSources
inlinter.getResult()
.Is there anything you'd like reviewers to focus on?
Supports multiple calls to
lint()
, but fixes in other files are ignored. Is that OK?CHANGELOG.md entry:
[api] add
dryRun
toLinter
.