-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Import eslint-plugin-tslint #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
6a46adc
tmp
JamesHenry 7c01721
Initial commit
JamesHenry 81c4285
Initial commit
JamesHenry 5f15a2f
Update README.md
JamesHenry f10695a
ci(.travis.yml): Add travis, semantic-release and conventional-changelog
JamesHenry 583c7e3
ci(_travis.yml): Configure travis script
JamesHenry 321c9a0
feat(index): Initial release
JamesHenry b9a0322
ci(.travis.yml): Fix indentation
JamesHenry 1b4b467
Remove old lib
JamesHenry bd6a442
fix(package.json): Run build during semantic-release
JamesHenry 5457735
fix(package.json): Add files to include lib in package
JamesHenry dbb2689
Update README.md
JamesHenry 519001f
refactor(src): Refactor the plugin to use TSLint 5 (#4)
JamesHenry 085d345
feat(failure message): Reference TSLint rule that failed (#5)
JamesHenry a708fce
chore(travis): Whitelist greenkeeper branches (#6)
greenkeeper[bot] 682fec5
ci(.travis.yml): Add greenkeeper-lockfile support (#7)
JamesHenry 20f4a40
chore(package): Update eslint to version 4.12.0 (#8)
greenkeeper[bot] 7547540
chore(package): Update typescript to to version 2.6.2 (#9)
greenkeeper[bot] 3903bca
chore(package): Update typescript-eslint-parser to version 9.0.1 (#10)
greenkeeper[bot] a92b8f3
chore(package): Update eslint to version 4.12.1 (#11)
greenkeeper[bot] 0a96614
chore(package): Update lint-staged to to version 6.0.0 (#12)
greenkeeper[bot] 8948768
chore(README): Banner URL
JamesHenry 74afd3f
chore(package): Update @types/node to version 8.0.54
greenkeeper[bot] 508dc35
chore(package): Update prettier-eslint-cli to version 4.4.2
JamesHenry 03f1576
chore(package): Update eslint to version 4.13.0 (#17)
greenkeeper[bot] 5046dd6
chore(package): Update @types/node to version 8.0.57 (#18)
JamesHenry bf6ccc9
chore(package): Update typescript-eslint-parser to version 10.0.0 (#19)
greenkeeper[bot] 406ab1a
chore(package): Update @types/node to version 8.0.58 (#20)
greenkeeper[bot] 59e1a55
chore(package): update eslint to version 4.13.1
greenkeeper[bot] f8a2291
feat(core): Added support rules requires type information
7ef8c53
chore: Removed old infrastructure code
dbfdb1e
style: Changed indent to 4 spaces
14d6cb4
refactor: Rewritten always-fail-rule in es2015 style
2ac5756
chore: Disabled package-lock
57edd3d
docs: Updated README
14648da
ci: Added missing packages
92ab381
chore(release): 2.2.0 [skip ci]
semantic-release-bot 2cd2a22
fix: Fixed bug when file not defined in tsconfig
1a5d92c
chore(release): 2.2.1 [skip ci]
semantic-release-bot 1b3f9ed
fix: Pass sourceText parameter to service getSource
500efd5
test: Read real code from test file
7599fc6
chore(release): 2.2.2 [skip ci]
semantic-release-bot cab2bd5
fix: Updated typescript-service dependency
13a280a
chore(release): 2.2.3 [skip ci]
semantic-release-bot 1c14cb8
fix: Update program when sourceFile was updated
7f0e7ad
chore(release): 2.2.4 [skip ci]
semantic-release-bot 2a1f9ef
docs: Main description
eae233c
test: Replaced jest by mocha
544935c
chore: Updated dependencies
3b3dc00
test: Added coverage
dc31589
feat: Post merge adapdation from tslint2 repository
4c68866
ci: Added install before deploy stage
dbfe392
ci: Fixed deployment
9296385
chore(release): 3.0.0 [skip ci]
semantic-release-bot eea5bff
docs: Added link to another tslint plugin
3fc7e87
chore(package): update typescript-eslint-parser to version 19.0.1
greenkeeper[bot] 2e6776e
feat: Support for tslint property
699142f
fix: Tiny lint note elimination
81f4204
chore: Updated dependencies
b900bf4
docs: Updated README
9eba5a8
chore(release): 3.1.0 [skip ci]
semantic-release-bot 9fa85a5
feat(plugin-tslint): updates for monorepo
JamesHenry 74d628b
docs: add issue template, remove migration note
JamesHenry 8ff2856
chore: remove force-local flag
JamesHenry f54d5cb
feat(plugin-tslint): remove service, use parserServices
JamesHenry 3e1a01f
chore: run tests in parallel
JamesHenry 494e247
fix(plugin-tslint): remove unsupported options
JamesHenry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
name: eslint-plugin-tslint | ||
about: Report an issue with the eslint-plugin-tslint package | ||
--- | ||
|
||
**What version of Node.js and npm are you using?** | ||
|
||
- Node: <!-- Please fill in --> | ||
- npm: <!-- Please fill in --> | ||
|
||
**What version of the following packages are you using?** | ||
|
||
- eslint-plugin-tslint: <!-- Please fill in --> | ||
- @typescript-eslint/parser: <!-- Please fill in --> | ||
- TypeScript: <!-- Please fill in --> | ||
- ESLint: <!-- Please fill in --> | ||
|
||
**What code were you trying to parse?** | ||
|
||
```ts | ||
// Please put code here | ||
``` | ||
|
||
**What did you expect to happen?** | ||
|
||
**What actually happened?** |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# [3.1.0](https://github.com/JamesHenry/eslint-plugin-tslint/compare/v3.0.0...v3.1.0) (2018-10-19) | ||
|
||
### Bug Fixes | ||
|
||
- Tiny lint note elimination ([a731838](https://github.com/JamesHenry/eslint-plugin-tslint/commit/a731838)) | ||
|
||
### Features | ||
|
||
- Support for tslint property ([18a4afb](https://github.com/JamesHenry/eslint-plugin-tslint/commit/18a4afb)), closes [#40](https://github.com/JamesHenry/eslint-plugin-tslint/issues/40) | ||
|
||
# [3.0.0](https://github.com/JamesHenry/eslint-plugin-tslint/compare/v2.1.0...v3.0.0) (2018-09-09) | ||
|
||
### Bug Fixes | ||
|
||
- Fixed bug when file not defined in tsconfig ([20b498b](https://github.com/JamesHenry/eslint-plugin-tslint/commit/20b498b)) | ||
- Pass sourceText parameter to service getSource ([dd4c2f8](https://github.com/JamesHenry/eslint-plugin-tslint/commit/dd4c2f8)) | ||
- Update program when sourceFile was updated ([0fe933c](https://github.com/JamesHenry/eslint-plugin-tslint/commit/0fe933c)) | ||
- Updated typescript-service dependency ([2f4f434](https://github.com/JamesHenry/eslint-plugin-tslint/commit/2f4f434)) | ||
|
||
### Features | ||
|
||
- **core:** Added support rules requires type information ([6bc1deb](https://github.com/JamesHenry/eslint-plugin-tslint/commit/6bc1deb)), closes [#32](https://github.com/JamesHenry/eslint-plugin-tslint/issues/32) [#34](https://github.com/JamesHenry/eslint-plugin-tslint/issues/34) | ||
- Post merge adapdation from tslint2 repository ([477c656](https://github.com/JamesHenry/eslint-plugin-tslint/commit/477c656)), closes [#32](https://github.com/JamesHenry/eslint-plugin-tslint/issues/32) [#34](https://github.com/JamesHenry/eslint-plugin-tslint/issues/34) | ||
|
||
### BREAKING CHANGES | ||
|
||
- New dependency |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 James Henry | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# ESLint Plugin TSLint | ||
|
||
[](https://travis-ci.org/JamesHenry/eslint-plugin-tslint) | ||
[](https://github.com/JamesHenry/eslint-plugin-tslint/blob/master/LICENSE) | ||
[](https://www.npmjs.com/package/eslint-plugin-tslint) | ||
[](https://www.npmjs.com/package/eslint-plugin-tslint) | ||
[](http://commitizen.github.io/cz-cli/) | ||
[](https://github.com/semantic-release/semantic-release) | ||
[](https://greenkeeper.io) | ||
|
||
ESLint plugin wraps a TSLint configuration and lints the whole source using TSLint. | ||
|
||
## INSTALL | ||
|
||
``` | ||
npm i -D eslint-plugin-tslint | ||
``` | ||
|
||
## USAGE | ||
|
||
Configure in your eslint config file: | ||
|
||
``` | ||
"plugins": [ | ||
"tslint" | ||
], | ||
"rules": { | ||
"tslint/config": ["warn", { | ||
lintFile: '/* path to tslint.json of your project */', | ||
rules: { /* tslint rules (will be used if `lintFile` is not specified) */ }, | ||
rulesDirectory: [ /* array of paths to directories with rules, e.g. 'node_modules/tslint/lib/rules' (will be used if `lintFile` is not specified) */ ] | ||
}], | ||
} | ||
``` | ||
|
||
## RULES | ||
|
||
Plugin contains only single rule `tslint/config`. | ||
|
||
## EXAMPLES | ||
|
||
- [unlight/node-package-starter/.eslintrc.js](https://github.com/unlight/node-package-starter/blob/master/.eslintrc.js) | ||
|
||
### TSLint Plugins | ||
|
||
- https://github.com/Glavin001/tslint-clean-code | ||
- https://github.com/Microsoft/tslint-microsoft-contrib | ||
- https://github.com/SonarSource/SonarTS | ||
- https://github.com/ajafff/tslint-consistent-codestyle |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
}, | ||
testRegex: './tests/.+\\.spec\\.ts$', | ||
collectCoverage: false, | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
coverageReporters: ['text-summary', 'lcov'] | ||
}; |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "eslint-plugin-tslint", | ||
"version": "3.1.0", | ||
"main": "dist/index.js", | ||
"typings": "src/index.ts", | ||
"author": "James Henry <typescript-eslint@jameshenry.blog>", | ||
"contributors": [ | ||
"Roman Vasilev (https://github.com/unlight)" | ||
], | ||
"description": "TSLint wrapper plugin for ESLint", | ||
"keywords": [ | ||
"eslint", | ||
"eslintplugin", | ||
"eslint-plugin", | ||
"tslint" | ||
], | ||
"repository": "typescript-eslint/typescript-eslint", | ||
"bugs": { | ||
"url": "https://github.com/typescript-eslint/typescript-eslint/issues" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "jest --coverage", | ||
"prebuild": "npm run clean", | ||
"build": "tsc", | ||
"clean": "rm -rf dist/" | ||
}, | ||
"dependencies": { | ||
"lodash.memoize": "^4.1.2" | ||
}, | ||
"peerDependencies": { | ||
"tslint": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/eslint": "^4.16.3", | ||
"@types/lodash.memoize": "^4.1.4", | ||
"@typescript-eslint/parser": "21.0.2", | ||
"tslint": "^5.11.0" | ||
} | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ILinterOptions, Linter, LintResult } from 'tslint'; | ||
import { Program } from 'typescript'; | ||
|
||
const TSLintLinter = Linter as any; | ||
|
||
export class CustomLinter extends TSLintLinter { | ||
constructor(options: ILinterOptions, private program: Program) { | ||
super(options, program); | ||
} | ||
|
||
getResult(): LintResult { | ||
return super.getResult(); | ||
} | ||
|
||
getSourceFile(fileName: string) { | ||
const result = this.program.getSourceFile(fileName); | ||
return result; | ||
} | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import { Rule } from 'eslint'; | ||
import memoize from 'lodash.memoize'; | ||
import { Configuration, RuleSeverity } from 'tslint'; | ||
import { Program } from 'typescript'; | ||
import { CustomLinter } from './custom-linter'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Plugin Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
/** | ||
* @todo share types between packages | ||
*/ | ||
interface ParserServices { | ||
program: Program | undefined; | ||
esTreeNodeToTSNodeMap: WeakMap<object, any> | undefined; | ||
tsNodeToESTreeNodeMap: WeakMap<object, any> | undefined; | ||
} | ||
|
||
type RawRuleConfig = | ||
| null | ||
| undefined | ||
| boolean | ||
| any[] | ||
| { | ||
severity?: RuleSeverity | 'warn' | 'none' | 'default'; | ||
options?: any; | ||
}; | ||
|
||
interface RawRulesConfig { | ||
[key: string]: RawRuleConfig; | ||
} | ||
|
||
/** | ||
* Construct a configFile for TSLint | ||
*/ | ||
const tslintConfig = memoize( | ||
( | ||
lintFile: string, | ||
tslintRules: RawRulesConfig, | ||
tslintRulesDirectory: string[] | ||
) => { | ||
if (lintFile != null) { | ||
return Configuration.loadConfigurationFromPath(lintFile); | ||
} | ||
return Configuration.parseConfigFile({ | ||
rules: tslintRules || {}, | ||
rulesDirectory: tslintRulesDirectory || [] | ||
}); | ||
}, | ||
(lintFile: string | undefined, tslintRules = {}, tslintRulesDirectory = []) => | ||
`${lintFile}_${Object.keys(tslintRules).join(',')}_${ | ||
tslintRulesDirectory.length | ||
}` | ||
); | ||
|
||
export const rules = { | ||
/** | ||
* Expose a single rule called "config", which will be accessed in the user's eslint config files | ||
* via "tslint/config" | ||
*/ | ||
config: { | ||
meta: { | ||
docs: { | ||
description: | ||
'Wraps a TSLint configuration and lints the whole source using TSLint', | ||
category: 'TSLint' | ||
}, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
rules: { | ||
type: 'object', | ||
/** | ||
* No fixed schema properties for rules, as this would be a permanently moving target | ||
*/ | ||
additionalProperties: true | ||
}, | ||
rulesDirectory: { | ||
type: 'array', | ||
items: { | ||
type: 'string' | ||
} | ||
}, | ||
lintFile: { | ||
type: 'string' | ||
} | ||
}, | ||
additionalProperties: false | ||
} | ||
] | ||
}, | ||
create: function(context: Rule.RuleContext) { | ||
const fileName = context.getFilename(); | ||
const sourceCode = context.getSourceCode().text; | ||
const parserServices: ParserServices | undefined = context.parserServices; | ||
armano2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* The user needs to have configured "project" in their parserOptions | ||
* for @typescript-eslint/parser | ||
*/ | ||
if (!parserServices || !parserServices.program) { | ||
throw new Error( | ||
`You must provide a value for the "parserOptions.project" property for @typescript-eslint/parser` | ||
); | ||
} | ||
|
||
/** | ||
* The TSLint rules configuration passed in by the user | ||
*/ | ||
const { | ||
rules: tslintRules, | ||
rulesDirectory: tslintRulesDirectory, | ||
lintFile | ||
} = context.options[0]; | ||
|
||
const program: Program = parserServices.program; | ||
|
||
/** | ||
* Create an instance of TSLint | ||
* Lint the source code using the configured TSLint instance, and the rules which have been | ||
* passed via the ESLint rule options for this rule (using "tslint/config") | ||
*/ | ||
const tslintOptions = { | ||
formatter: 'json', | ||
fix: false | ||
}; | ||
const tslint = new CustomLinter(tslintOptions, program); | ||
const configuration = tslintConfig( | ||
lintFile, | ||
tslintRules, | ||
tslintRulesDirectory | ||
); | ||
tslint.lint(fileName, sourceCode, configuration); | ||
|
||
const result = tslint.getResult(); | ||
|
||
/** | ||
* Format the TSLint results for ESLint | ||
*/ | ||
if (result.failures && result.failures.length) { | ||
result.failures.forEach(failure => { | ||
const start = failure.getStartPosition().getLineAndCharacter(); | ||
const end = failure.getEndPosition().getLineAndCharacter(); | ||
context.report({ | ||
message: `${failure.getFailure()} (tslint:${failure.getRuleName()})`, | ||
loc: { | ||
start: { | ||
line: start.line + 1, | ||
column: start.character | ||
}, | ||
end: { | ||
line: end.line + 1, | ||
column: end.character | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Return an empty object for the ESLint rule | ||
*/ | ||
return {}; | ||
} | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you can use
Record<string, RawRuleConfig)
here