Last active
May 14, 2019 09:51
-
-
Save andrewborisov/1ddf8636cd65d25099e053ab5cb1b532 to your computer and use it in GitHub Desktop.
creating-ts-lint-rule project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Linter, Configuration } from 'tslint'; | |
import * as TSLintConfig from '../tslint.json'; | |
// This utility helps to test ts-lint custom rules | |
export const lintHelper = ({ sourceFile, ruleName }: { sourceFile: string, ruleName: string }) => { | |
const lint = new Linter( { fix: false }); | |
const getRuleOptions = TSLintConfig.rules[ruleName]; | |
lint.lint('', sourceFile, Configuration.parseConfigFile({ | |
rules: { | |
[ruleName]: Array.isArray(getRuleOptions) ? [...getRuleOptions] : getRuleOptions, | |
}, | |
rulesDirectory: TSLintConfig.rulesDirectory, | |
})); | |
return lint.getResult(); | |
}; | |
// This utility helps to retrieve error lines | |
export const getErrorLines = (failures: any[]) => { | |
return failures.map((failure) => { | |
const start = failure.startPosition.position; | |
const end = failure.endPosition.position; | |
return failure.sourceFile.text.substr(start, failure.sourceFile.text.length - end); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment