1

I'm working on an angular2 project and have included grunt-tslint to improve my code. The grunt task "tslint" and default grunt task is workink fine but when I include it to the watch task it's not linting. I tried to delete every other watch task but also not working.

This are my versions:
grunt: v1.0.1
grunt-contrib-watch: 1.0.0
grunt-ts: v6.0.0-beta.3
grunt-tslint: 4.0.0

And the grunt tasks:

module.exports = function (grunt) {

grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),
    tslint: {
        options: {
            configuration: "tslint.json",
            force: false,
            fix: false
        },
        files: {
            src: ['app/**/*.ts']
        }
    },
    ts: {
        default : {
            src: ['app/**/*.ts'],
            outDir: 'outDir/app/',
            tsconfig: './tsconfig.json'
        }
    },

watch: {
        tslint: {
            files: ['app/**/*.ts'],
            task: ['tslint']
        },
        ts: {
            files: ['app/**/*.ts'],
            tasks: ['ts']
        }
    }
});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-tslint');

grunt.registerTask('default', [
    'ts', 'tslint'
]);

grunt.registerTask('validate:ts', ['tslint']);

};

trololololol
  • 113
  • 1
  • 8

2 Answers2

1

I think I found a solution. The watch task was watching the folder with two task (ts and tslint) and it was only runing ts (the last task). I combined both and now it's working:

        ts: {
            files: ['app/**/*.ts'],
            tasks: ['ts', 'tslint']
        }
trololololol
  • 113
  • 1
  • 8
0

UPDATE:

Try replacing your watch task with the following instead:

watch: {
    ts: {
        files: ['app/**/*.ts'],
        tasks: ['tslint', 'ts']
    }
}

Note:

  1. The target named tslint has been deleted from your watch task.
  2. The call to run the tslint task has now been added to the tasks array of the ts target.

Now when you run $ grunt watch the files will be:

  1. Linted using tslint according to the rules defined in tslint.json.
  2. If they PASS that check they will be transpiled with grunt-ts.
  3. If they FAIL that check no files will be transpiled, and any errors will be reported to the CLI.

Hope this helps!


PREVIOUS ANSWER:

One potential solution is to try reverting to the last stable version of the grunt-ts package.

To do this:

  1. cd to your project directory.

  2. Uninstall the current version of grunt-ts:

$ npm uninstall grunt-ts --save-dev

  1. Then install the last stable release of grunt-ts (which appears to be 5.5.1)

$ npm install grunt-ts@5.5.1 --save-dev

NOTE: I recommend trying the above with a copy of your project directory to see whether its successful !

RobC
  • 22,977
  • 20
  • 73
  • 80
  • thanks for your hint. I try it but it is still not working. But I think it's better to use the stabel version in the end and I "updated" it to v5.5.1 – trololololol Jan 12 '17 at 15:39