@definitelytyped/dtslint 0.0.95-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dt.json +15 -0
- package/dtslint-expect-only.json +6 -0
- package/dtslint.json +131 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
`dtslint` tests a TypeScript declaration file for style and correctness.
|
|
2
|
+
It will install `typescript` and `tslint` for you, so this is the only tool you need to test a type definition.
|
|
3
|
+
|
|
4
|
+
Lint rules new to dtslint are documented in the [docs](docs) directory.
|
|
5
|
+
|
|
6
|
+
# Just looking for ExpectType and ExpectError?
|
|
7
|
+
|
|
8
|
+
[Use tsd instead](https://github.com/SamVerschueren/tsd).
|
|
9
|
+
|
|
10
|
+
# Setup
|
|
11
|
+
|
|
12
|
+
If you are working on DefinitelyTyped, read the [DefinitelyTyped README](https://github.com/DefinitelyTyped/DefinitelyTyped#readme).
|
|
13
|
+
|
|
14
|
+
If you are writing the library in TypeScript, don't use `dtslint`.
|
|
15
|
+
Use [`--declaration`](http://www.typescriptlang.org/docs/handbook/compiler-options.html) to have type definitions generated for you.
|
|
16
|
+
|
|
17
|
+
If you are a library author, read below.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Add types for a library (not on DefinitelyTyped)
|
|
21
|
+
|
|
22
|
+
[`dts-gen`](https://github.com/Microsoft/dts-gen#readme) may help, but is not required.
|
|
23
|
+
|
|
24
|
+
Create a `types` directory. (Name is arbitrary.)
|
|
25
|
+
Add `"types": "types"` to your `package.json`.
|
|
26
|
+
Read more on bundling types [here](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html).
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#### `types/index.d.ts`
|
|
30
|
+
|
|
31
|
+
Only `index.d.ts` needs to be published to NPM. Other files are just for testing.
|
|
32
|
+
Write your type definitions here.
|
|
33
|
+
Refer to the [handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) or `dts-gen`'s templates for how to do this.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
#### `types/tsconfig.json`
|
|
37
|
+
|
|
38
|
+
```json5
|
|
39
|
+
{
|
|
40
|
+
"compilerOptions": {
|
|
41
|
+
"module": "commonjs",
|
|
42
|
+
"lib": ["es6"],
|
|
43
|
+
"noImplicitAny": true,
|
|
44
|
+
"noImplicitThis": true,
|
|
45
|
+
"strictFunctionTypes": true,
|
|
46
|
+
"strictNullChecks": true,
|
|
47
|
+
"types": [],
|
|
48
|
+
"noEmit": true,
|
|
49
|
+
"forceConsistentCasingInFileNames": true,
|
|
50
|
+
|
|
51
|
+
// If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index".
|
|
52
|
+
// If the library is global (cannot be imported via `import` or `require`), leave this out.
|
|
53
|
+
"baseUrl": ".",
|
|
54
|
+
"paths": { "mylib": ["."] }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
You may extend `"lib"` to, for example, `["es6", "dom"]` if you need those typings.
|
|
60
|
+
You may also have to add `"target": "es6"` if using certain language features.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#### `types/tslint.json`
|
|
64
|
+
|
|
65
|
+
If you are using the default rules, this is optional.
|
|
66
|
+
|
|
67
|
+
If present, this will override `dtslint`'s [default](https://github.com/Microsoft/dtslint/blob/master/dtslint.json) settings.
|
|
68
|
+
You can specify new lint [rules](https://palantir.github.io/tslint/rules/), or disable some. An example:
|
|
69
|
+
|
|
70
|
+
```json5
|
|
71
|
+
{
|
|
72
|
+
"extends": "dtslint/dtslint.json", // Or "dtslint/dt.json" if on DefinitelyTyped
|
|
73
|
+
"rules": {
|
|
74
|
+
"semicolon": false,
|
|
75
|
+
"indent": [true, "tabs"]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
#### `types/test.ts`
|
|
82
|
+
|
|
83
|
+
You can have any number of test files you want, with any names. See below on what to put in them.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## Write tests
|
|
88
|
+
|
|
89
|
+
A test file should be a piece of sample code that tests using the library. Tests are type-checked, but not run.
|
|
90
|
+
To assert that an expression is of a given type, use `$ExpectType`.
|
|
91
|
+
To assert that an expression causes a compile error, use `$ExpectError`.
|
|
92
|
+
(Assertions will be checked by the `expect` lint rule.)
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { f } from "my-lib"; // f is(n: number) => void
|
|
96
|
+
|
|
97
|
+
// $ExpectType void
|
|
98
|
+
f(1);
|
|
99
|
+
|
|
100
|
+
// Can also write the assertion on the same line.
|
|
101
|
+
f(2); // $ExpectType void
|
|
102
|
+
|
|
103
|
+
// $ExpectError
|
|
104
|
+
f("one");
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## Specify a TypeScript version
|
|
109
|
+
|
|
110
|
+
Normally packages will be tested using TypeScript 2.0.
|
|
111
|
+
To use a newer version, specify it by including a comment like so:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// Minimum TypeScript Version: 2.1
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
For DefinitelyTyped packages, this should go just under the header (on line 5).
|
|
118
|
+
For bundled typings, this can go on any line (but should be near the top).
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Run tests
|
|
122
|
+
|
|
123
|
+
- `npm install --save-dev dtslint`
|
|
124
|
+
- Add to your `package.json` `scripts`: `"dtslint": "dtslint types"`
|
|
125
|
+
- `npm run dtslint`
|
|
126
|
+
|
|
127
|
+
### Options
|
|
128
|
+
|
|
129
|
+
- `--localTs`
|
|
130
|
+
|
|
131
|
+
Use your locally installed version of TypeScript.
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
dtslint --localTs node_modules/typescript/lib types
|
|
135
|
+
```
|
|
136
|
+
- `--expectOnly`
|
|
137
|
+
|
|
138
|
+
Disable all the lint rules except the one that checks for type correctness.
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
dtslint --expectOnly types
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# Contributing
|
|
146
|
+
|
|
147
|
+
## Build
|
|
148
|
+
|
|
149
|
+
```sh
|
|
150
|
+
npm link . # Global 'dts-lint' should now refer to this.
|
|
151
|
+
npm run watch
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Test
|
|
155
|
+
|
|
156
|
+
Use `npm run test` to run all tests.
|
|
157
|
+
To run a single test: `node node_modules/tslint/bin/tslint --rules-dir bin/rules --test test/expect`.
|
|
158
|
+
|
|
159
|
+
## Publish
|
|
160
|
+
|
|
161
|
+
1. Change the version in the `package.json`
|
|
162
|
+
2. Push to master
|
|
163
|
+
|
|
164
|
+
## Code of Conduct
|
|
165
|
+
|
|
166
|
+
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 [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
167
|
+
|
|
168
|
+
## FAQ
|
|
169
|
+
I'm getting an error about a missing typescript install.
|
|
170
|
+
```
|
|
171
|
+
Error: Cannot find module '/node_modules/dtslint/typescript-installs/3.1/node_modules/typescript`
|
|
172
|
+
```
|
|
173
|
+
Your dependencies may be out of date.
|
|
174
|
+
[@definitelytyped/typescript-versions](https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/typescript-versions) is the package that contains the list of TypeScript versions to install.
|
|
175
|
+
|
|
176
|
+
Alternatively this error can be caused by concurrent dtslint invocations trampling each other's TypeScript installations, especially in the context of continuous integration, if dtslint is installed from scratch in each run.
|
|
177
|
+
If for example you use [Lerna](https://github.com/lerna/lerna/tree/main/commands/run#readme), try running dtslint with [`lerna --concurrency 1 run ...`](https://github.com/lerna/lerna/tree/main/core/global-options#--concurrency).
|
package/dt.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./dtslint.json",
|
|
3
|
+
"rules": {
|
|
4
|
+
"dt-header": true,
|
|
5
|
+
"no-bad-reference": true,
|
|
6
|
+
"no-declare-current-package": true,
|
|
7
|
+
"no-self-import": true,
|
|
8
|
+
"no-outside-dependencies": true,
|
|
9
|
+
|
|
10
|
+
"no-redundant-jsdoc": false,
|
|
11
|
+
"no-redundant-jsdoc-2": true,
|
|
12
|
+
|
|
13
|
+
"npm-naming": [true, { "mode": "code" }]
|
|
14
|
+
}
|
|
15
|
+
}
|
package/dtslint.json
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "tslint:all",
|
|
3
|
+
"rulesDirectory": "./bin/rules",
|
|
4
|
+
"rules": {
|
|
5
|
+
// Custom rules
|
|
6
|
+
"expect": true,
|
|
7
|
+
"export-just-namespace": true,
|
|
8
|
+
"no-bad-reference": true,
|
|
9
|
+
"no-const-enum": true,
|
|
10
|
+
"no-dead-reference": true,
|
|
11
|
+
"no-import-default-of-export-equals": true,
|
|
12
|
+
"no-padding": true,
|
|
13
|
+
"redundant-undefined": true,
|
|
14
|
+
"no-relative-import-in-test": true,
|
|
15
|
+
"strict-export-declare-modifiers": true,
|
|
16
|
+
"no-any-union": true,
|
|
17
|
+
"no-single-declare-module": true,
|
|
18
|
+
"no-unnecessary-generics": true,
|
|
19
|
+
"no-useless-files": true,
|
|
20
|
+
"prefer-declare-function": true,
|
|
21
|
+
"trim-file": true,
|
|
22
|
+
"unified-signatures": true,
|
|
23
|
+
"void-return": true,
|
|
24
|
+
"npm-naming": true,
|
|
25
|
+
|
|
26
|
+
"comment-format": [true, "check-space"], // But not check-uppercase or check-lowercase
|
|
27
|
+
"interface-name": [true, "never-prefix"],
|
|
28
|
+
"max-line-length": [true, 200],
|
|
29
|
+
"member-access": [true, "no-public"],
|
|
30
|
+
"no-consecutive-blank-lines": true,
|
|
31
|
+
"no-unnecessary-callback-wrapper": true,
|
|
32
|
+
"no-namespace": [true, "allow-declarations"],
|
|
33
|
+
"object-literal-key-quotes": [true, "as-needed"],
|
|
34
|
+
"one-line": [
|
|
35
|
+
true,
|
|
36
|
+
"check-catch",
|
|
37
|
+
"check-finally",
|
|
38
|
+
"check-else",
|
|
39
|
+
"check-open-brace",
|
|
40
|
+
"check-whitespace"
|
|
41
|
+
],
|
|
42
|
+
"one-variable-per-declaration": [true, "ignore-for-loop"],
|
|
43
|
+
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"],
|
|
44
|
+
"prefer-template": [true, "allow-single-concat"],
|
|
45
|
+
"whitespace": [
|
|
46
|
+
true,
|
|
47
|
+
"check-branch",
|
|
48
|
+
"check-decl",
|
|
49
|
+
"check-operator",
|
|
50
|
+
"check-module",
|
|
51
|
+
"check-separator",
|
|
52
|
+
"check-type",
|
|
53
|
+
"check-typecast"
|
|
54
|
+
],
|
|
55
|
+
|
|
56
|
+
// TODO?
|
|
57
|
+
"align": false, // TODO
|
|
58
|
+
"arrow-parens": false,
|
|
59
|
+
"arrow-return-shorthand": true, // TODO: "multiline"
|
|
60
|
+
"linebreak-style": false, // TODO
|
|
61
|
+
"no-void-expression": [true, "ignore-arrow-function-shorthand"],
|
|
62
|
+
"no-any": false, // TODO
|
|
63
|
+
"no-floating-promises": false, // TODO: https://github.com/palantir/tslint/issues/2879
|
|
64
|
+
"no-import-side-effect": false,
|
|
65
|
+
"no-this-assignment": false,
|
|
66
|
+
"no-unbound-method": false, // TODO?
|
|
67
|
+
"no-unsafe-any": false, // TODO
|
|
68
|
+
"no-restricted-globals": false,
|
|
69
|
+
"number-literal-format": false, // TODO
|
|
70
|
+
"promise-function-async": false,
|
|
71
|
+
"restrict-plus-operands": false, // TODO
|
|
72
|
+
"return-undefined": false, // TODO
|
|
73
|
+
"switch-final-break": false, // TODO
|
|
74
|
+
"prefer-method-signature": false, // TODO?
|
|
75
|
+
|
|
76
|
+
// Pretty sure we don't want these
|
|
77
|
+
"binary-expression-operand-order": false,
|
|
78
|
+
"class-name": false,
|
|
79
|
+
"completed-docs": false,
|
|
80
|
+
"curly": false,
|
|
81
|
+
"cyclomatic-complexity": false,
|
|
82
|
+
"deprecation": false,
|
|
83
|
+
"file-name-casing": false,
|
|
84
|
+
"forin": false,
|
|
85
|
+
"indent": false,
|
|
86
|
+
"match-default-export-name": false,
|
|
87
|
+
"max-classes-per-file": false,
|
|
88
|
+
"max-file-line-count": false,
|
|
89
|
+
"member-ordering": false,
|
|
90
|
+
"newline-before-return": false,
|
|
91
|
+
"newline-per-chained-call": false,
|
|
92
|
+
"no-bitwise": false,
|
|
93
|
+
"no-console": false,
|
|
94
|
+
"no-default-export": false,
|
|
95
|
+
"no-empty": false,
|
|
96
|
+
"no-implicit-dependencies": false, // See https://github.com/palantir/tslint/issues/3364
|
|
97
|
+
"no-inferred-empty-object-type": false,
|
|
98
|
+
"no-magic-numbers": false,
|
|
99
|
+
"no-non-null-assertion": false,
|
|
100
|
+
"no-null-keyword": false,
|
|
101
|
+
"no-parameter-properties": false,
|
|
102
|
+
"no-parameter-reassignment": false,
|
|
103
|
+
"no-reference": false, // But see no-bad-reference
|
|
104
|
+
"no-require-imports": false,
|
|
105
|
+
"no-shadowed-variable": false,
|
|
106
|
+
"no-string-literal": false,
|
|
107
|
+
"no-submodule-imports": false,
|
|
108
|
+
"no-tautology-expression": false,
|
|
109
|
+
"no-unused-expression": false,
|
|
110
|
+
"no-unused-variable": false,
|
|
111
|
+
"no-use-before-declare": false,
|
|
112
|
+
"object-literal-sort-keys": false,
|
|
113
|
+
"ordered-imports": false,
|
|
114
|
+
"prefer-function-over-method": false,
|
|
115
|
+
"quotemark": false,
|
|
116
|
+
"strict-boolean-expressions": false,
|
|
117
|
+
"strict-type-predicates": false,
|
|
118
|
+
"switch-default": false,
|
|
119
|
+
"trailing-comma": false,
|
|
120
|
+
"triple-equals": [true, "allow-null-check"],
|
|
121
|
+
"typedef": false,
|
|
122
|
+
"type-literal-delimiter": false,
|
|
123
|
+
"variable-name": false,
|
|
124
|
+
"increment-decrement": false,
|
|
125
|
+
"unnecessary-constructor": false,
|
|
126
|
+
"unnecessary-else": false,
|
|
127
|
+
"no-angle-bracket-type-assertion": false,
|
|
128
|
+
"no-default-import": false,
|
|
129
|
+
"callable-types": false
|
|
130
|
+
}
|
|
131
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@definitelytyped/dtslint",
|
|
3
|
+
"version": "0.0.95-next.1",
|
|
4
|
+
"description": "Runs tests on TypeScript definition files",
|
|
5
|
+
"files": [
|
|
6
|
+
"bin",
|
|
7
|
+
"dt.json",
|
|
8
|
+
"dtslint.json",
|
|
9
|
+
"dtslint-expect-only.json"
|
|
10
|
+
],
|
|
11
|
+
"main": "bin",
|
|
12
|
+
"bin": "./bin/index.js",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"contributors": [
|
|
17
|
+
"Nathan Shively-Sanders <nathansa@microsoft.com> (https://github.com/sandersn)",
|
|
18
|
+
"Andy Hanson <andy-ms@microsoft.com> (https://github.com/andy-ms)",
|
|
19
|
+
"Dan Vanderkam <danvdk@gmail.com> (https://github.com/danvk)"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/microsoft/DefinitelyTyped-tools.git"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"watch": "tsc --watch",
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"lint": "eslint --ext ts src",
|
|
29
|
+
"test": "npm run build && node test/test.js"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@definitelytyped/dts-critic": "^0.0.95-next.1",
|
|
33
|
+
"@definitelytyped/header-parser": "0.0.93",
|
|
34
|
+
"@definitelytyped/typescript-versions": "0.0.93",
|
|
35
|
+
"@definitelytyped/utils": "0.0.93",
|
|
36
|
+
"fs-extra": "^6.0.1",
|
|
37
|
+
"json-stable-stringify": "^1.0.1",
|
|
38
|
+
"strip-json-comments": "^2.0.1",
|
|
39
|
+
"tslint": "5.14.0",
|
|
40
|
+
"yargs": "^15.1.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"typescript": ">= 3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.7.0-dev || >= 3.8.0-dev || >= 3.9.0-dev || >= 4.0.0-dev"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/fs-extra": "^5.0.2",
|
|
47
|
+
"@types/json-stable-stringify": "^1.0.32",
|
|
48
|
+
"@types/node": "14.0.x",
|
|
49
|
+
"@types/strip-json-comments": "^0.0.28",
|
|
50
|
+
"@types/yargs": "^15.0.3",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^4.11.1",
|
|
52
|
+
"@typescript-eslint/parser": "^4.11.1",
|
|
53
|
+
"eslint": "^7.16.0",
|
|
54
|
+
"typescript": "next"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=10.0.0"
|
|
58
|
+
},
|
|
59
|
+
"license": "MIT",
|
|
60
|
+
"gitHead": "dc40b825ec231899cb63a5b007da08c463f2ee7d"
|
|
61
|
+
}
|