panuhorsmalahti / gulp-tslint

TypeScript linter plugin for Gulp
MIT License
118 stars 44 forks source link

Using tsProject.src() does not work #137

Open TiTi opened 6 years ago

TiTi commented 6 years ago

Hi,

My gulp-tslint had no output compared to tslint alone :-( I've realized this happens because I'm using tsProject.src() rather than gulp.src("FlexibleForm/**/*.ts") with const tsProject = ts.createProject('FlexibleForm/tsconfig.json'); Thus I found a workaround. But I'd like to share this issue and I have some questions:

The gulp-typescript documentation tells us:

You can replace gulp.src(...) with tsProject.src() to load files based on the tsconfig file (based on files, excludes and includes).

And it works fine in my task 'transpile-ts'. This is why I found it handy for my gulp-tslint task...


gulp-tslint version: 8.1.2 tslint version: 5.6.0 Operating system: Windows 10

Failing gulp configuration:

const gulpTslint = require("gulp-tslint");
const ts = require("gulp-typescript");
const tsProject = ts.createProject('FlexibleForm/tsconfig.json');

gulp.task("tslint", function ()
{
    return tsProject.src()
        .pipe(gulpTslint(
        {
            formatter: "stylish"
        }))
        .pipe(gulpTslint.report());
});

Console output, no linter warnings/error :

H:\FlexibleFormTypeScript>gulp tslint [16:05:37] Using gulpfile H:\FlexibleFormTypeScript\gulpfile.js [16:05:37] Starting 'tslint'... [16:05:37] Finished 'tslint' after 187 ms

H:\FlexibleFormTypeScript>

However, calling tslint manually, I do have some errors... H:\FlexibleFormTypeScript>node node_modules\tslint\bin\tslint -p FlexibleForm/tsconfig.json --format stylish ERROR...


Tree:

+---gulpfile.js
+---tslint.json
+---package.json
+---FlexibleForm
|   +---tsconfig.json
|   +---FlexibleForm.ts
|   +---(other .ts files)
|   +---(some .d.ts files)
+---node_modules
    +---.bin
    +---...

So I have a tslint.json at top and a FlexibleForm/tsconfig.json under. The idea is that I have other typescript project next to FlexibleForm/, but I want them to reference the same tslint.json. Is this hierarchy the cause of my issue?

FlexibleForm/tsconfig.json:

{
    "files":
    [
        "FlexibleForm.ts"
    ],
    "include":
    [
        "**/*.d.ts"
    ],
    "compilerOptions":
    {
        "target": "es5",
        "module": "amd",
        "moduleResolution": "classic",
        "outFile": "FlexibleForm.js",
        "inlineSourceMap": true,
        "lib": ["es5", "dom", "es2015.iterable"]
    }
}

Working version:

const gulpTslint = require("gulp-tslint");
const ts = require("gulp-typescript");
const tsProject = ts.createProject('FlexibleForm/tsconfig.json');

gulp.task("tslint", function ()
{
    return gulp.src("FlexibleForm/**/*.ts") // CHANGE HERE
        .pipe(gulpTslint(
        {
            formatter: "stylish"
        }))
        .pipe(gulpTslint.report());
});

I get:

H:\FlexibleFormTypeScript>gulp tslint [16:25:44] Using gulpfile H:\FlexibleFormTypeScript\gulpfile.js [16:25:44] Starting 'tslint'... H:/FlexibleFormTypeScript/FlexibleForm/Layout/Footer.ts ERROR: 21:52 quotemark ' should be "

H:/FlexibleFormTypeScript/FlexibleForm/Layout/Header.ts ERROR: 22:5 comment-format comment must start with a space ERROR: 44:1 max-line-length Exceeds maximum line length of 140 ERROR: 51:1 no-trailing-whitespace trailing whitespace ERROR: 57:1 no-trailing-whitespace trailing whitespace

H:/FlexibleFormTypeScript/FlexibleForm/Layout/_Containers.ts ERROR: 11:2 object-literal-sort-keys The key 'Footer' is not sorted alphabetically ERROR: 3:1 ordered-imports Import sources within a group must be alphabetized.

[16:25:44] 'tslint' errored after 484 ms [16:25:44] Error in plugin 'gulp-tslint' Message:.....

Thus, I found an acceptable workaround. But: