Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Track and restore initial or previous rule state for one line lint switches (fixes #1624) #1634

Merged
merged 10 commits into from
Nov 27, 2016

Conversation

IllusionMH
Copy link
Contributor

@IllusionMH IllusionMH commented Oct 16, 2016

This PR makes EnableDisableRulesWalker aware of initial rules configuration for file.
This allows track rule state during file parsing and restore proper rule state after it was disabled for single line (with disable-line or disable-next-line switchers).

Todo:

  • Handle tslint:(disable|enable) cases
  • Add tests for enable-line and enable-next-line switchers (it was early morning and I've missed that this rules aren't documented)
  • Do not add new entries to enableDisableRuleMap if rule state doesn't change

ETA: October, 23rd

@IllusionMH IllusionMH changed the title [WIP] Track and restore initial or previous rule state for one line lint switches (fixes #1624) Track and restore initial or previous rule state for one line lint switches (fixes #1624) Oct 23, 2016
@IllusionMH
Copy link
Contributor Author

I've updated this pull request with rework for how enabled/disabled states are tracked for file.
Notable changes:

  • Rule switchers are tracked only for rules that are enabled in configuration (rules that wouldn't be executed in any case)
  • Switch positions are only added in case when state for rule changes (this allow to be sure that states in enableDisableRuleMap always alternate which simplifies generation of disabled intervals)
  • If switch is performed for all rules - all of them are manually switched if needed (further simplifies generation of disabled intervals)

I've removed test cases for enable-line and enable-next-line from TODO list since this feature isn't documented for TSLint (ESLint also).
@adidahiya @jkillian should this feature be supported (I'll add test cases if needed) or may be it should show warnings for developers (since it might be error prone to count on rule that are enabled only for one line in disabled interval) ?

At this point I think that work is finished and PR is ready for review.

@IllusionMH
Copy link
Contributor Author

I haven't found any docs on my question so I want to clarify it here: What is proper way for this repo to make branch up to date with master - git rebase master or git merge master?

@nchen63
Copy link
Contributor

nchen63 commented Nov 12, 2016

It doesn't matter if you merge or rebase since we just squash the commit before merging into master

@IllusionMH IllusionMH force-pushed the enable-disable-line-fix branch from 99a8f7f to 0e26676 Compare November 12, 2016 03:48
@@ -164,19 +164,19 @@ class MultiLinter {

private getEnabledRules(fileName: string, source?: string, configuration: IConfigurationFile = DEFAULT_CONFIG): IRule[] {
const sourceFile = this.getSourceFile(fileName, source);
const isJs = fileName.substr(-3) === ".js";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found this during PR update.
I believe that this check should include .jsx files too. Something like /\.jsx?$/i.test(fileName)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good catch

@IllusionMH
Copy link
Contributor Author

Rebased and updated PR with recent changes in master.

@IllusionMH IllusionMH mentioned this pull request Nov 13, 2016
4 tasks
@IllusionMH IllusionMH force-pushed the enable-disable-line-fix branch from 0e26676 to 471d162 Compare November 16, 2016 00:07
Copy link
Contributor

@nchen63 nchen63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good in general. The enable-line and enable-next-line cases still work right? Like nothing blows up?

});

if (end) {
// switchRule method is only called when rule state changes therefore we can safely use opposite state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switchRule -> switchRuleState

* We're assuming both lists are already sorted top-down so compare the tops, use the smallest of the two,
* and build the intervals that way.
/**
* creates disabled intervals for rule based on list of swithers for it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swithers -> switchers

}

// use same logic as in AbstractRule
function isEnabled(value: any): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

factor out and put in Utils

@IllusionMH
Copy link
Contributor Author

@nchen63 thank you for review.

The enable-line and enable-next-line cases still work right? Like nothing blows up?

Yes. Actually there already were tests for enable-line/enable-next-line switchers.

factor out and put in Utils

src/utils.ts contains only basic utility functions without any rules related functionality.
Therefore I decided to move logic from instance isEnabled method to static method which still belongs to AbstractRule.
But if you insist - I'll move it to utils.

@nchen63 nchen63 merged commit f1df7b7 into palantir:master Nov 27, 2016
@nchen63
Copy link
Contributor

nchen63 commented Nov 27, 2016

@IllusionMH Looks good. Thanks!

@IllusionMH IllusionMH deleted the enable-disable-line-fix branch November 27, 2016 12:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants