Skip to content

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 67 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
6a46adc
tmp
JamesHenry Jan 17, 2019
7c01721
Initial commit
JamesHenry Dec 28, 2016
81c4285
Initial commit
JamesHenry Dec 28, 2016
5f15a2f
Update README.md
JamesHenry Dec 29, 2016
f10695a
ci(.travis.yml): Add travis, semantic-release and conventional-changelog
JamesHenry Dec 29, 2016
583c7e3
ci(_travis.yml): Configure travis script
JamesHenry Dec 29, 2016
321c9a0
feat(index): Initial release
JamesHenry Dec 29, 2016
b9a0322
ci(.travis.yml): Fix indentation
JamesHenry Dec 29, 2016
1b4b467
Remove old lib
JamesHenry Dec 29, 2016
bd6a442
fix(package.json): Run build during semantic-release
JamesHenry Dec 29, 2016
5457735
fix(package.json): Add files to include lib in package
JamesHenry Dec 29, 2016
dbb2689
Update README.md
JamesHenry Dec 29, 2016
519001f
refactor(src): Refactor the plugin to use TSLint 5 (#4)
JamesHenry Nov 24, 2017
085d345
feat(failure message): Reference TSLint rule that failed (#5)
JamesHenry Nov 24, 2017
a708fce
chore(travis): Whitelist greenkeeper branches (#6)
greenkeeper[bot] Nov 26, 2017
682fec5
ci(.travis.yml): Add greenkeeper-lockfile support (#7)
JamesHenry Nov 26, 2017
20f4a40
chore(package): Update eslint to version 4.12.0 (#8)
greenkeeper[bot] Nov 29, 2017
7547540
chore(package): Update typescript to to version 2.6.2 (#9)
greenkeeper[bot] Dec 1, 2017
3903bca
chore(package): Update typescript-eslint-parser to version 9.0.1 (#10)
greenkeeper[bot] Dec 1, 2017
a92b8f3
chore(package): Update eslint to version 4.12.1 (#11)
greenkeeper[bot] Dec 1, 2017
0a96614
chore(package): Update lint-staged to to version 6.0.0 (#12)
greenkeeper[bot] Dec 1, 2017
8948768
chore(README): Banner URL
JamesHenry Dec 2, 2017
74afd3f
chore(package): Update @types/node to version 8.0.54
greenkeeper[bot] Dec 4, 2017
508dc35
chore(package): Update prettier-eslint-cli to version 4.4.2
JamesHenry Dec 4, 2017
03f1576
chore(package): Update eslint to version 4.13.0 (#17)
greenkeeper[bot] Dec 11, 2017
5046dd6
chore(package): Update @types/node to version 8.0.57 (#18)
JamesHenry Dec 11, 2017
bf6ccc9
chore(package): Update typescript-eslint-parser to version 10.0.0 (#19)
greenkeeper[bot] Dec 11, 2017
406ab1a
chore(package): Update @types/node to version 8.0.58 (#20)
greenkeeper[bot] Dec 11, 2017
59e1a55
chore(package): update eslint to version 4.13.1
greenkeeper[bot] Dec 12, 2017
f8a2291
feat(core): Added support rules requires type information
Aug 24, 2018
7ef8c53
chore: Removed old infrastructure code
Aug 25, 2018
dbfdb1e
style: Changed indent to 4 spaces
Aug 25, 2018
14d6cb4
refactor: Rewritten always-fail-rule in es2015 style
Aug 25, 2018
2ac5756
chore: Disabled package-lock
Aug 25, 2018
57edd3d
docs: Updated README
Aug 25, 2018
14648da
ci: Added missing packages
Aug 25, 2018
92ab381
chore(release): 2.2.0 [skip ci]
semantic-release-bot Aug 25, 2018
2cd2a22
fix: Fixed bug when file not defined in tsconfig
Aug 25, 2018
1a5d92c
chore(release): 2.2.1 [skip ci]
semantic-release-bot Aug 25, 2018
1b3f9ed
fix: Pass sourceText parameter to service getSource
Aug 25, 2018
500efd5
test: Read real code from test file
Aug 25, 2018
7599fc6
chore(release): 2.2.2 [skip ci]
semantic-release-bot Aug 25, 2018
cab2bd5
fix: Updated typescript-service dependency
Aug 26, 2018
13a280a
chore(release): 2.2.3 [skip ci]
semantic-release-bot Aug 26, 2018
1c14cb8
fix: Update program when sourceFile was updated
Aug 26, 2018
7f0e7ad
chore(release): 2.2.4 [skip ci]
semantic-release-bot Aug 26, 2018
2a1f9ef
docs: Main description
Aug 27, 2018
eae233c
test: Replaced jest by mocha
Aug 28, 2018
544935c
chore: Updated dependencies
Aug 28, 2018
3b3dc00
test: Added coverage
Aug 31, 2018
dc31589
feat: Post merge adapdation from tslint2 repository
Sep 5, 2018
4c68866
ci: Added install before deploy stage
Sep 6, 2018
dbfe392
ci: Fixed deployment
Sep 6, 2018
9296385
chore(release): 3.0.0 [skip ci]
semantic-release-bot Sep 9, 2018
eea5bff
docs: Added link to another tslint plugin
Sep 12, 2018
3fc7e87
chore(package): update typescript-eslint-parser to version 19.0.1
greenkeeper[bot] Sep 25, 2018
2e6776e
feat: Support for tslint property
Oct 19, 2018
699142f
fix: Tiny lint note elimination
Oct 19, 2018
81f4204
chore: Updated dependencies
Oct 19, 2018
b900bf4
docs: Updated README
Oct 19, 2018
9eba5a8
chore(release): 3.1.0 [skip ci]
semantic-release-bot Oct 19, 2018
9fa85a5
feat(plugin-tslint): updates for monorepo
JamesHenry Jan 17, 2019
74d628b
docs: add issue template, remove migration note
JamesHenry Jan 17, 2019
8ff2856
chore: remove force-local flag
JamesHenry Jan 17, 2019
f54d5cb
feat(plugin-tslint): remove service, use parserServices
JamesHenry Jan 17, 2019
3e1a01f
chore: run tests in parallel
JamesHenry Jan 17, 2019
494e247
fix(plugin-tslint): remove unsupported options
JamesHenry Jan 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/eslint-plugin-tslint.md
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?**
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ This repo contains several packages which allow ESLint users to lint their TypeS

- `eslint-plugin-tslint` - An ESLint-specific plugin which runs an instance of TSLint within your ESLint setup to allow for users to more easily migrate from TSLint to ESLint.

- PENDING MIGRATION TO MONOREPO

## Supported TypeScript Version

We will always endeavor to support the latest stable version of TypeScript.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"url": "https://github.com/typescript-eslint/typescript-eslint/issues"
},
"scripts": {
"postinstall": "lerna bootstrap && lerna link",
"test": "lerna run test",
"postinstall": "lerna bootstrap && yarn build && lerna link",
"test": "lerna run test --parallel",
"build": "lerna run build",
"clean": "lerna run clean",
"clean": "lerna clean && lerna run clean",
"precommit": "yarn test && lint-staged",
"cz": "git-cz",
"commitmsg": "commitlint -E GIT_PARAMS",
Expand Down
27 changes: 27 additions & 0 deletions packages/eslint-plugin-tslint/CHANGELOG.md
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
21 changes: 21 additions & 0 deletions packages/eslint-plugin-tslint/LICENSE
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.
49 changes: 49 additions & 0 deletions packages/eslint-plugin-tslint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ESLint Plugin TSLint

[![Travis](https://img.shields.io/travis/JamesHenry/eslint-plugin-tslint.svg?style=flat-square)](https://travis-ci.org/JamesHenry/eslint-plugin-tslint)
[![GitHub license](https://img.shields.io/npm/l/eslint-plugin-tslint.svg?style=flat-square)](https://github.com/JamesHenry/eslint-plugin-tslint/blob/master/LICENSE)
[![NPM Version](https://img.shields.io/npm/v/eslint-plugin-tslint.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-tslint)
[![NPM Downloads](https://img.shields.io/npm/dt/eslint-plugin-tslint.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-tslint)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
[![greenkeeper.io](https://badges.greenkeeper.io/JamesHenry/mongoose-schema-to-typescript-interface.svg?style=flat-square)](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
13 changes: 13 additions & 0 deletions packages/eslint-plugin-tslint/jest.config.js
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']
};
40 changes: 40 additions & 0 deletions packages/eslint-plugin-tslint/package.json
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"
}
}
19 changes: 19 additions & 0 deletions packages/eslint-plugin-tslint/src/custom-linter.ts
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;
}
}
168 changes: 168 additions & 0 deletions packages/eslint-plugin-tslint/src/index.ts
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,
Copy link
Collaborator

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

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;

/**
* 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 {};
}
}
};
Loading