mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-27 00:15:09 +08:00
Start using linter
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -31,6 +31,7 @@ _infrastructure/tests/build
|
||||
*.js.map
|
||||
!*.js/
|
||||
!scripts/new-package.js
|
||||
!scripts/lint.js
|
||||
|
||||
node_modules
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
Please fill in this template.
|
||||
|
||||
- [ ] Prefer to make your PR against the `types-2.0` branch.
|
||||
- [ ] The package does not provide its own types, and you can not add them.
|
||||
- [ ] Test the change in your own code.
|
||||
- [ ] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped#make-a-pull-request).
|
||||
- [ ] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped#common-mistakes).
|
||||
- [ ] Run `npm run lint -- package-name` if a `tslint.json` is present.
|
||||
|
||||
If adding a new definition:
|
||||
- [ ] The package does not provide its own types, and you can not add them.
|
||||
- [ ] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package.
|
||||
- [ ] Run `tsc` without errors.
|
||||
- [ ] Include the required [files](https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package) and header.
|
||||
- [ ] Include the required [files](https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package) and header. Base these on the README, *not* on an existing project.
|
||||
|
||||
If changing an existing definition:
|
||||
- [ ] Provide a URL to documentation or source code which provides context for the suggested changes: <<url here>>
|
||||
|
||||
22
README.md
22
README.md
@@ -117,6 +117,7 @@ DefinitelyTyped members routinely monitor for new PRs, though keep in mind that
|
||||
|
||||
For a good example package, see [base64-js](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/base64-js).
|
||||
|
||||
|
||||
#### Common mistakes
|
||||
|
||||
* First, follow advice from the [handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html).
|
||||
@@ -153,6 +154,27 @@ Make a PR doing the following:
|
||||
To do this, add a `package.json` with `"dependencies": { "foo": "x.y.z" }`.
|
||||
|
||||
|
||||
#### Lint
|
||||
|
||||
To lint a package, just add a `tslint.json` to that package containing `{ "extends": "../tslint.json" }`. All new packages must be linted.
|
||||
If a `tslint.json` turns rules off, this is because that hasn't been fixed yet. For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": "../tslint.json",
|
||||
"rules": {
|
||||
// This package uses the Function type, and it will take effort to fix.
|
||||
"forbidden-types": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
(To indicate that a lint rule truly does not apply, use `// tslint:disable:rule-name` or better, `//tslint:disable-next-line:rule-name`.)
|
||||
|
||||
Only `.d.ts` files are linted.
|
||||
Test the linter by running `npm run lint -- package-name`. Do not use a globally installed tslint.
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
#### What exactly is the relationship between this repository and the `@types` packages on NPM?
|
||||
|
||||
1
base64-js/tslint.json
Normal file
1
base64-js/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
@@ -17,6 +17,7 @@
|
||||
"scripts": {
|
||||
"compile-scripts": "tsc -p scripts",
|
||||
"new-package": "node scripts/new-package.js",
|
||||
"lint": "node scripts/lint.js",
|
||||
"test": "node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed --nProcesses 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
11
scripts/lint.js
Normal file
11
scripts/lint.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// Usage: npm run lint -- my-package-name
|
||||
const pkg = process.argv[2];
|
||||
const execSync = require("child_process").execSync;
|
||||
const cmd = `node node_modules/tslint/lib/tslint-cli --format stylish ${pkg}/**/*.d.ts`;
|
||||
console.log(cmd);
|
||||
try {
|
||||
// Child process writes directly to our own stdout
|
||||
execSync(cmd, { stdio: "inherit" });
|
||||
} catch (_) {
|
||||
// Process should have printed out error info
|
||||
}
|
||||
@@ -36,6 +36,7 @@ const tsconfig = {
|
||||
]
|
||||
};
|
||||
write("tsconfig.json", JSON.stringify(tsconfig, undefined, 4));
|
||||
write("tslint.json", '{ "extends": "../tslint.json" }');
|
||||
function write(name, content) {
|
||||
fs_1.writeFileSync(path.join(newPackageName, name), content);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ const tsconfig = {
|
||||
};
|
||||
write("tsconfig.json", JSON.stringify(tsconfig, undefined, 4));
|
||||
|
||||
write("tslint.json", '{ "extends": "../tslint.json" }');
|
||||
|
||||
function write(name: string, content: string) {
|
||||
writeFileSync(path.join(newPackageName, name), content);
|
||||
}
|
||||
|
||||
1
tslint.json
Normal file
1
tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "./node_modules/types-publisher/tslint-definitions.json" }
|
||||
Reference in New Issue
Block a user