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

Move dtscritic to tslint rule #218

Merged
merged 8 commits into from
Mar 22, 2019
Merged

Conversation

sandersn
Copy link
Member

Now it's possible to turn it off!

Since it reads from the file system, it is hard to test with tslint's test framework. I tested it manually instead.

Because dts-critic inspects the filesystem, and the test filesystem has
extra .lint extensions, and I don't care enough to make it
understand the tslint test environment.
I had to hack dts-critic though, with a new entry point:

```js
/** @param {string} dts - the text of the d.ts */
dtsCritic.alternate = function (dts, dtsPath) {
    let header;
    try {
        header = headerParser.parseHeaderOrFail(dts);
    }
    catch(e) {
        header = undefined;
    }
    const names = findNames(dtsPath, undefined, header)
    const src = download("https://unpkg.com/" + mangleScoped(names.src));
    checkNames(names, header);
    if (header && !header.nonNpm) {
        checkSource(names.dts, dts, src);
    }
}
```

and modified findDtsName to know about .lint extension in tests. This
second thing is not good and should probably be inverted as well:

```
/**
 * If dtsName is 'index' (as with DT) then look to the parent directory for the name.
 * @param {string} dtsPath
 */
function findDtsName(dtsPath) {
    const resolved = path.resolve(dtsPath);
    const baseName = path.basename(resolved, '.d.ts');
    if (baseName && baseName !== "index") {
        const baseName2 = path.basename(resolved, '.d.ts.lint');
        if (baseName2 && baseName2 !== "index") {
            return baseName;
        }
    }
    return path.basename(path.dirname(resolved));
}
```
@sandersn sandersn merged commit 12d5edf into master Mar 22, 2019
@sandersn sandersn deleted the move-dtscritic-to-tslint-rule branch March 22, 2019 16:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant