A set of coding standard settings for use with https://eslint.org/. Eslint is source code checking framework used to enforce coding standards.
To use this npm module:
- Install
- Configure Grunt
- (Optional) Configure Visual Studio Code
npm install --save @ravdocs/eslint;
-
Install grunt-eslint.
npm install --save-dev grunt-eslint;
-
Create a new file in the grunt tasks folder (e.g.
grunts/eslint.js
) with this content:'use strict'; module.exports = function(grunt) { grunt.config('eslint', { options: { rulePaths: ['node_modules/@ravdocs/eslint/rules'] }, backend: { options: { configFile: 'node_modules/@ravdocs/eslint/configs/backend.js' }, src: [ '*.js', 'grunts/**/*.js', // <file-patterns-here> ] }, frontend: { options: { configFile: 'node_modules/@ravdocs/eslint/configs/frontend.js' }, src: [ // <file-patterns-here> ] } }); grunt.loadNpmTasks('grunt-eslint'); };
-
Fill out
<file-patterns-here>
in thebackend.src
andfrontend.src
arrays. (additional info here) -
Update
gruntfile.js
to include this configuration:'use strict'; var Pkg = require('./package.json'); module.exports = function(grunt) { grunt.initConfig({ pkg: Pkg }); grunt.loadTasks('grunts'); grunt.registerTask('check', [ 'eslint' ]); grunt.registerTask('lint', [ 'eslint' ]); grunt.registerTask('build', [ 'check' //additional tasks here ]); grunt.registerTask('default', [ 'check' ]); };
-
Test with
grunt
andgrunt lint
.
NOTE: This is optional.
-
Open
Settings
.- OS X: ⌘,
- Linux: CTRL,
-
Add to
USER SETTINGS
:"eslint.autoFixOnSave": true, "eslint.options": { "rulePaths": [ "node_modules/@ravdocs/eslint/rules" ] },
-
Create
.eslintrc.js
in the top-level directory of the repo (next topackage.json
) with this content:'use strict'; module.exports = require('@ravdocs/eslint').configs.backend;
-
Create another
.eslintrc.js
in the directory containing frontend files (e.g.,public/.eslintrc.js
) with this content:'use strict'; module.exports = require('@ravdocs/eslint').configs.frontend;