Skip to content

Commit

Permalink
Start using linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Nov 16, 2016
1 parent a23bd35 commit b599125
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ _infrastructure/tests/build
*.js.map
!*.js/
!scripts/new-package.js
!scripts/lint.js

node_modules

Expand Down
5 changes: 3 additions & 2 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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>>
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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?
Expand Down
1 change: 1 addition & 0 deletions base64-js/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 11 additions & 0 deletions scripts/lint.js
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions scripts/new-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions scripts/new-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "./node_modules/types-publisher/tslint-definitions.json" }

0 comments on commit b599125

Please sign in to comment.