Sumeet Kumar Yadav
Sumeet Kumar Yadav

Reputation: 12995

Multiple eslintrc in grunt pointing to different folder

I have folder structure like below and using eslint I am validating my syntax rules .

I have a grunt file which runs eslint by default to all folder below src . But now I have got new scenario where I need to run few more rules to one specific folder mddx. Along With default rules mddx should run with more rules .

I know we can have multiple .eslintrc.json file , but how to configure in gruntfile.js with two task , both doing eslint but rules are diffrent. Also pointing folder is different.

parent
 |
 |
 |------src
 |        +mund
 |            |
 |            |--<jsfiles>
 |        +mddx
 |            |
 |            |--<jsfiles>
 .eslintrc.json
 |
 |
 gruntfile.js
 |

gruntfile.js

module.exports = function(grunt) {

    require('load-grunt-tasks')(grunt);

    grunt.initConfig({
        eslint: {
            options: {
                config: '.eslintrc.json',
                reset: false
            },
            target: {
              src: [
                'src/**/*.js'
              ]
            }
        }
    });


    grunt.registerTask('default', ['eslint']);

};

Upvotes: 2

Views: 503

Answers (1)

Sumeet Kumar Yadav
Sumeet Kumar Yadav

Reputation: 12995

I got answer so posting it . Created .eslintrc.json file specific to folder and divided eslint into two sub task . Both has different configuration and points to different rule and folder.

module.exports = function(grunt) {
    require('load-grunt-tasks')(grunt);
    grunt.initConfig({
        eslint: {
            default: {
                options: {
                    configFile: '.eslintrc.json',
                    reset: false
                },
                src: [
                    'src/**/*.js'
                ]
            },
            mddx: {
                options: {
                    configFile: 'src/mddx/.eslintrc.json',
                    reset: false
                },
                src: [
                    'src/mddx/**/*.js'
                ]
            }
        }
    });

    grunt.registerTask('default', ['eslint']);
};

Upvotes: 1

Related Questions