diff --git a/generators/linting/README.md b/generators/linting/README.md new file mode 100644 index 0000000..fa9bc2a --- /dev/null +++ b/generators/linting/README.md @@ -0,0 +1,15 @@ +# linting + +Installs linter dependencies and creates lint configuration files. + +## Usage + +Run generator from root of the project that needs linting. + +``` +$ yo springworks:linting +``` + +## Result + +NPM modules will be installed and `.eslintrc` created in `.` and `./test` dir. diff --git a/generators/linting/index.js b/generators/linting/index.js new file mode 100644 index 0000000..79adb60 --- /dev/null +++ b/generators/linting/index.js @@ -0,0 +1,49 @@ +'use strict'; + +const path = require('path'); +const generators = require('yeoman-generator'); + +module.exports = generators.Base.extend({ + + constructor: function() { + generators.Base.apply(this, arguments); + }, + + initializing: function() { + const welcomeMessage = [ + '\nSetting up linting\n', + ]; + this.log(welcomeMessage.join('')); + }, + + writing: { + + linterConfigs: function() { + this.copy('.eslintrc', '.eslintrc'); + this.copy(path.join('test', '.eslintrc'), path.join('test', '.eslintrc')); + }, + + linterIgnoreFile: function() { + this.copy('.eslintignore', '.eslintignore'); + }, + + }, + + install: { + + installDependencies: function() { + const dependencies = [ + 'babel-eslint', + 'eslint', + 'eslint-config-springworks', + 'eslint-plugin-import', + 'eslint-plugin-mocha', + 'eslint-plugin-should-promised', + 'eslint-plugin-springworks', + ]; + this.npmInstall(dependencies, { saveDev: true }); + }, + + }, + +}); diff --git a/generators/linting/templates/.eslintignore b/generators/linting/templates/.eslintignore new file mode 100644 index 0000000..8446242 --- /dev/null +++ b/generators/linting/templates/.eslintignore @@ -0,0 +1,5 @@ +.idea +.iml +coverage +node_modules +packages/** diff --git a/generators/linting/templates/.eslintrc b/generators/linting/templates/.eslintrc new file mode 100644 index 0000000..ee50106 --- /dev/null +++ b/generators/linting/templates/.eslintrc @@ -0,0 +1,5 @@ +{ + "extends": "springworks/babel", + "rules": { + } +} diff --git a/generators/linting/templates/test/.eslintrc b/generators/linting/templates/test/.eslintrc new file mode 100644 index 0000000..7fe5a9d --- /dev/null +++ b/generators/linting/templates/test/.eslintrc @@ -0,0 +1,13 @@ +{ + "extends": "springworks/mocha", + "globals": { + "should": false, + "sinon": false + }, + "plugins": [ + "should-promised" + ], + "rules": { + "should-promised/return-promise": 2 + } +} diff --git a/test/linting-test.js b/test/linting-test.js new file mode 100644 index 0000000..1684052 --- /dev/null +++ b/test/linting-test.js @@ -0,0 +1,30 @@ +'use strict'; + +const path = require('path'); +const assert = require('yeoman-assert'); +const helpers = require('yeoman-test'); + +describe('test/linting-test.js', () => { + + before(done => { + helpers.run(path.join(__dirname, '..', 'generators', 'linting')) + .withOptions({ + 'skip-install': true, + }) + .withPrompts() + .on('end', done); + }); + + it('should copy .eslintrc to root dir', () => { + assert.file('.eslintrc'); + }); + + it('should copy .eslintrc to test dir', () => { + assert.file(path.join('test', '.eslintrc')); + }); + + it('should copy .eslintignore to root dir', () => { + assert.file('.eslintignore'); + }); + +});