Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/dtslint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3a94f6fa3b20d0f43ac759c54b3438072a57ef63
Choose a base ref
...
head repository: microsoft/dtslint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9c56a82bcb9705a00207a17eedce554119ce55e9
Choose a head ref
  • 2 commits
  • 10 files changed
  • 2 contributors

Commits on Feb 12, 2020

  1. Copy the full SHA
    c859e21 View commit details

Commits on Feb 14, 2020

  1. Update npm naming (#269)

    * Update npm-naming for new dts-critic
    
    * Remove logs
    
    * Fix tslint errors
    
    * Update node version
    
    * Update docs
    
    * fixes
    
    * Update npm-naming for new dts-critic
    
    * Remove logs
    
    * Fix tslint errors
    
    * Update node version
    
    * Update docs
    
    * fixes
    gabritto authored Feb 14, 2020
    Copy the full SHA
    9c56a82 View commit details
79 changes: 74 additions & 5 deletions docs/npm-naming.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

(This rule is specific to DefinitelyTyped.)

Checks that the name of the type package matches a source package on npm.
## Name checks
In 'name-only' mode, checks that the name of the type package matches a source package on npm.

---

@@ -12,7 +13,7 @@ Checks that the name of the type package matches a source package on npm.
// Type definitions for browser-only-package 1.2
```

* If the package is really browser-only, you have mark it with "non-npm package"
* If the package is really browser-only, you have to mark it with "non-npm package".
* If the package actually has a matching npm package, you must use that name.

**Good**:
@@ -37,6 +38,10 @@ Checks that the name of the type package matches a source package on npm.
// Type definitions for some-package 10.1
```

## Code checks

In 'code' mode, in addition to the name checks, this rule also checks that the source JavaScript code matches the declaration file for npm packages.

---

**Bad**:
@@ -55,14 +60,78 @@ module.exports = function () {
};
```

* A commonjs module.exports assignment is not really an export default, and the d.ts should use the `export =` syntax.
* `export default` can only be used to export a commonjs `module.exports =` when you have `esModuleInterop` turned on, which not everybody does.
* A CommonJs module.exports assignment is not really an export default, and the d.ts should use the [`export =`](https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require) syntax.
* `export default` can only be used to export a CommonJs `module.exports =` when you have `esModuleInterop` turned on, which not everybody does.

**Good**:

`foo/index.d.ts`:

```ts
function f(): void;
declare function f(): void;
export = f;
```

---

**Bad**:

`foo/index.d.ts`:

```ts
export class C {}
```

`foo/index.js`:

```js
module.exports = class C {}
```

* The CommonJs module is a class, which means it can be constructed, like this:
```js
var C = require('foo');
var x = new C();
```
However, the way `class C` is exported in the d.ts file (using an export declaration) means it can only be used like this:
```ts
var foo = require('foo');
var x = new foo.C();
```

* The d.ts should use [`export =`](https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require)
syntax to match the CommonJs module behavior.

**Good**:

`foo/index.d.ts`:

```ts
declare class C {}
export = C;
```

* If you need to use `export =` syntax as in the example above, and the source JavaScript also exports some properties,
you might need to use [*declaration merging*](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-namespaces-with-classes-functions-and-enums) in your d.ts. Example:

**JavaScript**:

`foo/index.js`:

```js
function foo() {};
foo.bar = "Exported property";
module.exports = foo; // module.exports is a function, but it also has a property called `bar`
```

**Declaration**:

`foo/index.d.ts`:

```ts
declare function foo(): void;
declare namespace foo {
var bar: string;
}
export = foo;
```
42 changes: 24 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dtslint",
"version": "2.0.5",
"version": "2.0.6",
"description": "Runs tests on TypeScript definition files",
"files": [
"bin",
@@ -28,19 +28,19 @@
},
"dependencies": {
"definitelytyped-header-parser": "3.8.2",
"dts-critic": "^2.2.4",
"dts-critic": "^3.0.0",
"fs-extra": "^6.0.1",
"strip-json-comments": "^2.0.1",
"tslint": "5.14.0",
"typescript": "next"
},
"devDependencies": {
"@types/fs-extra": "^5.0.2",
"@types/node": "^7.10.7",
"@types/node": "12.0.x",
"@types/strip-json-comments": "^0.0.28"
},
"engines": {
"node": ">=6.10.0"
"node": ">=12.0.0"
},
"license": "MIT"
}
Loading