Skip to content

Ignore rule if file is dirty#2175

Open
FunctionDJ wants to merge 2 commits into
microsoft:mainfrom
FunctionDJ:FunctionDJ/issue2171
Open

Ignore rule if file is dirty#2175
FunctionDJ wants to merge 2 commits into
microsoft:mainfrom
FunctionDJ:FunctionDJ/issue2171

Conversation

@FunctionDJ
Copy link
Copy Markdown

Closes #2171.

Adds an unsavedOnly boolean property to eslint.rules.customizations entries. When true, the customization only applies while the file has unsaved changes; once saved, the rule reports at its original severity.

Motivating use case: eslint-plugin-prettier is useful in CI but noisy during active editing. With this option you can suppress prettier/prettier while typing while still seeing violations in committed/saved code:

"eslint.rules.customizations": [
  { "rule": "prettier/prettier", "severity": "off", "unsavedOnly": true }
]

Implementation notes:

Dirty state is tracked server-side by recording the document version at open/save (textDocument/didOpen, textDocument/didSave) and comparing against the current version. This avoids a false-dirty state that would arise from using TextDocuments.onDidChangeContent, which fires for both didOpen and didChange notifications.

Because the pull diagnostics model doesn't automatically re-pull after a save when in-memory content is unchanged, onDidSave triggers connection.languages.diagnostics.refresh() so the updated dirty state is reflected immediately.

The RuleSeverities cache key is extended with the dirty flag (ruleId:0/1) so clean and dirty results are cached independently and invalidated correctly on settings change.

Human written AI Disclaimer: I used Copilot to help me with this implementation and the above PR text body, but I reviewed it, ran the mocha tests, used the Launch Config to test it, and iterated on the feature until it actually worked with Launch Config. I take responsibility for this code. I also looked into if there's a simpler way to determine if a document is dirty, but according to Copilot this would require a client-server roundtrip that's not necessary when the implementation in this PR also works server-side-only.

@FunctionDJ
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore rule if file is dirty

1 participant