This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Doodles: attempt to add ESLint, round 3 #341
Closed
JoshuaKGoldberg
wants to merge
3
commits into
microsoft:master
from
JoshuaKGoldberg:switch-to-eslint-3
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
`dtslint` tests a TypeScript declaration file for style and correctness. | ||
It will install `typescript` and `tslint` for you, so this is the only tool you need to test a type definition. | ||
It will install `typescript` and `eslint` for you, so this is the only tool you need to test a type definition. | ||
|
||
Lint rules new to dtslint are documented in the [docs](docs) directory. | ||
|
||
|
@@ -16,7 +16,6 @@ Use [`--declaration`](http://www.typescriptlang.org/docs/handbook/compiler-optio | |
|
||
If you are a library author, read below. | ||
|
||
|
||
## Add types for a library (not on DefinitelyTyped) | ||
|
||
[`dts-gen`](https://github.com/Microsoft/dts-gen#readme) may help, but is not required. | ||
|
@@ -25,14 +24,12 @@ Create a `types` directory. (Name is arbitrary.) | |
Add `"types": "types"` to your `package.json`. | ||
Read more on bundling types [here](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html). | ||
|
||
|
||
#### `types/index.d.ts` | ||
|
||
Only `index.d.ts` needs to be published to NPM. Other files are just for testing. | ||
Write your type definitions here. | ||
Refer to the [handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) or `dts-gen`'s templates for how to do this. | ||
|
||
|
||
#### `types/tsconfig.json` | ||
|
||
```json5 | ||
|
@@ -57,31 +54,26 @@ Refer to the [handbook](http://www.typescriptlang.org/docs/handbook/declaration- | |
You may extend `"lib"` to, for example, `["es6", "dom"]` if you need those typings. | ||
You may also have to add `"target": "es6"` if using certain language features. | ||
|
||
|
||
#### `types/tslint.json` | ||
#### `types/eslintrc.json` | ||
|
||
If you are using the default rules, this is optional. | ||
|
||
If present, this will override `dtslint`'s [default](https://github.com/Microsoft/dtslint/blob/master/dtslint.json) settings. | ||
You can specify new lint [rules](https://palantir.github.io/tslint/rules/), or disable some. An example: | ||
You can specify new lint [configuration](https://eslint.org/docs/user-guide/configuring), or disable some. An example: | ||
|
||
```json5 | ||
{ | ||
"extends": "dtslint/dtslint.json", // Or "dtslint/dt.json" if on DefinitelyTyped | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"semicolon": false, | ||
"indent": [true, "tabs"] | ||
"@typescript-eslint/no-floating-promises": false | ||
} | ||
} | ||
``` | ||
|
||
|
||
#### `types/test.ts` | ||
|
||
You can have any number of test files you want, with any names. See below on what to put in them. | ||
|
||
|
||
|
||
## Write tests | ||
|
||
A test file should be a piece of sample code that tests using the library. Tests are type-checked, but not run. | ||
|
@@ -102,7 +94,6 @@ f(2); // $ExpectType void | |
f("one"); | ||
``` | ||
|
||
|
||
## Specify a TypeScript version | ||
|
||
Normally packages will be tested using TypeScript 2.0. | ||
|
@@ -115,7 +106,6 @@ To use a newer version, specify it by including a comment like so: | |
For DefinitelyTyped packages, this should go just under the header (on line 5). | ||
For bundled typings, this can go on any line (but should be near the top). | ||
|
||
|
||
## Run tests | ||
|
||
- `npm install --save-dev dtslint` | ||
|
@@ -131,14 +121,6 @@ Use your locally installed version of TypeScript. | |
```sh | ||
dtslint --localTs node_modules/typescript/lib types | ||
``` | ||
- `--expectOnly` | ||
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. expectOnly is used by dtslint-runner to speed up linting in incremental mode for dependents, so that only packages a PR modifies actually run all the lint rules. Otherwise CI runs for node, react, et al take too long. |
||
|
||
Disable all the lint rules except the one that checks for type correctness. | ||
|
||
```sh | ||
dtslint --expectOnly types | ||
``` | ||
|
||
|
||
# Contributing | ||
|
||
|
@@ -152,7 +134,6 @@ npm run watch | |
## Test | ||
|
||
Use `npm run test` to run all tests. | ||
To run a single test: `node node_modules/tslint/bin/tslint --rules-dir bin/rules --test test/expect`. | ||
|
||
## Publish | ||
|
||
|
@@ -164,8 +145,11 @@ To run a single test: `node node_modules/tslint/bin/tslint --rules-dir bin/rules | |
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
|
||
## FAQ | ||
|
||
I'm getting an error about a missing typescript install. | ||
|
||
``` | ||
Error: Cannot find module '/node_modules/dtslint/typescript-installs/3.1/node_modules/typescript` | ||
``` | ||
|
||
Package lock files such as `yarn.lock` and `package-lock.json` may cause this issue because of our github dependency on `"definitelytyped-header-parser": "github:Microsoft/definitelytyped-header-parser#production"`, which contains the list of typescript versions to install. To fix this, try deleting your lock file and re-installing. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,30 @@ | ||
{ | ||
"extends": "tslint:all", | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking" | ||
], | ||
"rulesDirectory": "./bin/rules", | ||
"rules": { | ||
// Custom rules | ||
"expect": true, | ||
"export-just-namespace": true, | ||
"no-any-union": true, | ||
"no-bad-reference": true, | ||
"no-const-enum": true, | ||
"no-dead-reference": true, | ||
"no-import-default-of-export-equals": true, | ||
"no-padding": true, | ||
"redundant-undefined": true, | ||
"no-relative-import-in-test": true, | ||
"strict-export-declare-modifiers": true, | ||
"no-any-union": true, | ||
"no-single-declare-module": true, | ||
"no-unnecessary-generics": true, | ||
"no-useless-files": true, | ||
"npm-naming": true, | ||
"prefer-declare-function": true, | ||
"redundant-undefined": true, | ||
"strict-export-declare-modifiers": true, | ||
"trim-file": true, | ||
"unified-signatures": true, | ||
"void-return": true, | ||
"npm-naming": true, | ||
|
||
"comment-format": [true, "check-space"], // But not check-uppercase or check-lowercase | ||
"interface-name": [true, "never-prefix"], | ||
"max-line-length": [true, 200], | ||
"member-access": [true, "no-public"], | ||
"no-consecutive-blank-lines": true, | ||
"no-unnecessary-callback-wrapper": true, | ||
"no-namespace": [true, "allow-declarations"], | ||
"object-literal-key-quotes": [true, "as-needed"], | ||
"one-line": [ | ||
true, | ||
"check-catch", | ||
"check-finally", | ||
"check-else", | ||
"check-open-brace", | ||
"check-whitespace" | ||
], | ||
"one-variable-per-declaration": [true, "ignore-for-loop"], | ||
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"], | ||
"prefer-template": [true, "allow-single-concat"], | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-module", | ||
"check-separator", | ||
"check-type", | ||
"check-typecast" | ||
], | ||
|
||
// TODO? | ||
"align": false, // TODO | ||
"arrow-parens": false, | ||
"arrow-return-shorthand": true, // TODO: "multiline" | ||
"linebreak-style": false, // TODO | ||
"no-void-expression": [true, "ignore-arrow-function-shorthand"], | ||
"no-any": false, // TODO | ||
"no-floating-promises": false, // TODO: https://github.com/palantir/tslint/issues/2879 | ||
"no-import-side-effect": false, | ||
"no-this-assignment": false, | ||
"no-unbound-method": false, // TODO? | ||
"no-unsafe-any": false, // TODO | ||
"no-restricted-globals": false, | ||
"number-literal-format": false, // TODO | ||
"promise-function-async": false, | ||
"restrict-plus-operands": false, // TODO | ||
"return-undefined": false, // TODO | ||
"switch-final-break": false, // TODO | ||
"prefer-method-signature": false, // TODO? | ||
|
||
// Pretty sure we don't want these | ||
"binary-expression-operand-order": false, | ||
"class-name": false, | ||
"completed-docs": false, | ||
"curly": false, | ||
"cyclomatic-complexity": false, | ||
"deprecation": false, | ||
"file-name-casing": false, | ||
"forin": false, | ||
"indent": false, | ||
"match-default-export-name": false, | ||
"max-classes-per-file": false, | ||
"max-file-line-count": false, | ||
"member-ordering": false, | ||
"newline-before-return": false, | ||
"newline-per-chained-call": false, | ||
"no-bitwise": false, | ||
"no-console": false, | ||
"no-default-export": false, | ||
"no-empty": false, | ||
"no-implicit-dependencies": false, // See https://github.com/palantir/tslint/issues/3364 | ||
"no-inferred-empty-object-type": false, | ||
"no-magic-numbers": false, | ||
"no-non-null-assertion": false, | ||
"no-null-keyword": false, | ||
"no-parameter-properties": false, | ||
"no-parameter-reassignment": false, | ||
"no-reference": false, // But see no-bad-reference | ||
"no-require-imports": false, | ||
"no-shadowed-variable": false, | ||
"no-string-literal": false, | ||
"no-submodule-imports": false, | ||
"no-tautology-expression": false, | ||
"no-unused-expression": false, | ||
"no-unused-variable": false, | ||
"no-use-before-declare": false, | ||
"object-literal-sort-keys": false, | ||
"ordered-imports": false, | ||
"prefer-function-over-method": false, | ||
"quotemark": false, | ||
"strict-boolean-expressions": false, | ||
"strict-type-predicates": false, | ||
"switch-default": false, | ||
"trailing-comma": false, | ||
"triple-equals": [true, "allow-null-check"], | ||
"typedef": false, | ||
"type-literal-delimiter": false, | ||
"variable-name": false, | ||
"increment-decrement": false, | ||
"unnecessary-constructor": false, | ||
"unnecessary-else": false, | ||
"no-angle-bracket-type-assertion": false, | ||
"no-default-import": false, | ||
"callable-types": false | ||
"void-return": true | ||
} | ||
} |
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.
Todo: for now, it will still install
tslint
as well...