-
Notifications
You must be signed in to change notification settings - Fork 889
Rewrite enable/disable logic #2369
Changes from 13 commits
0a7ddf0
f7788e2
4bc3d4b
c416136
2b61c2d
d3da276
a8459c2
c8a31d0
a0c68b4
acb22e4
0d62d89
c3c819e
34f5df1
a364779
91990ff
9cdbb18
7036515
7551a4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,11 @@ | |
import * as ts from "typescript"; | ||
|
||
import {arrayify, flatMap} from "../../utils"; | ||
import {IWalker} from "../walker"; | ||
|
||
export interface RuleStatic { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a duplicate of |
||
metadata: IRuleMetadata; | ||
new(options: IOptions): IRule; | ||
} | ||
|
||
export interface RuleConstructor { | ||
metadata: IRuleMetadata; | ||
|
@@ -99,19 +103,12 @@ export interface IOptions { | |
ruleArguments: any[]; | ||
ruleSeverity: RuleSeverity; | ||
ruleName: string; | ||
disabledIntervals: IDisabledInterval[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be kept and deprecated for backwards compatibility |
||
} | ||
|
||
export interface IDisabledInterval { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
startPosition: number; | ||
endPosition: number; | ||
} | ||
|
||
export interface IRule { | ||
getOptions(): IOptions; | ||
isEnabled(): boolean; | ||
apply(sourceFile: ts.SourceFile): RuleFailure[]; | ||
applyWithWalker(walker: IWalker): RuleFailure[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method was never necessary to have here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should also not be removed for now |
||
} | ||
|
||
export interface ITypedRule extends IRule { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,21 +19,11 @@ import * as path from "path"; | |
import { isBlockScopedVariableDeclarationList } from "tsutils"; | ||
import * as ts from "typescript"; | ||
|
||
import {IDisabledInterval, RuleFailure} from "./rule/rule"; | ||
|
||
export function getSourceFile(fileName: string, source: string): ts.SourceFile { | ||
const normalizedName = path.normalize(fileName).replace(/\\/g, "/"); | ||
return ts.createSourceFile(normalizedName, source, ts.ScriptTarget.ES5, /*setParentNodes*/ true); | ||
} | ||
|
||
export function doesIntersect(failure: RuleFailure, disabledIntervals: IDisabledInterval[]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another breaking change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is public. (#2446) |
||
return disabledIntervals.some((interval) => { | ||
const maxStart = Math.max(interval.startPosition, failure.getStartPosition().getPosition()); | ||
const minEnd = Math.min(interval.endPosition, failure.getEndPosition().getPosition()); | ||
return maxStart <= minEnd; | ||
}); | ||
} | ||
|
||
/** | ||
* @returns true if any modifier kinds passed along exist in the given modifiers array | ||
*/ | ||
|
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.
breaking change. keep this method, just return the input unchanged and deprecate it