diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..714b9a57 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,25 @@ +{ + "extends": "standard", + "rules": { + "block-spacing": 0, + "brace-style": 0, + "comma-dangle": 0, + "indent": 0, + "key-spacing": 0, + "keyword-spacing": 0, + "no-duplicate-imports": 0, + "no-multiple-empty-lines": 0, + "no-path-concat": 0, + "no-throw-literal": 0, + "no-trailing-spaces": 0, + "no-unused-vars": 0, + "operator-linebreak": 0, + "padded-blocks": 0, + "quotes": 0, + "semi-spacing": 0, + "semi": 0, + "space-before-blocks": 0, + "space-before-function-paren": 0, + "space-infix-ops": 0 + } +} diff --git a/.travis.yml b/.travis.yml index 486fdf0d..5cba325d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ before_script: - npm prune - git version script: +- npm run lint - npm run test - npm run check-coverage after_success: diff --git a/appveyor.yml b/appveyor.yml index e331233b..2fd3aff5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,4 +26,4 @@ artifacts: name: test artifacts # Don't actually build. -build: off \ No newline at end of file +build: off diff --git a/package.json b/package.json index 2e391ba7..d5e99780 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "write-coverage": "nyc report --reporter=lcov", "semantic-release": "semantic-release pre && npm publish && semantic-release post", "start": "npm run test:watch", + "lint": "eslint --ignore-path .gitignore .", "test": "nyc --require babel-core/register _mocha -- test/tests/index.js", "test:watch": "nodemon -q --ignore test/.tmp/ --ignore test/artifacts/ --ignore coverage/ --exec \"npm run test\" --", "test:windows": "node ./test/tools/trigger-appveyor-tests.js" @@ -22,7 +23,7 @@ "path": "./node_modules/cz-conventional-changelog" }, "ghooks": { - "pre-commit": "npm run test && npm run check-coverage" + "pre-commit": "npm run lint && npm run test && npm run check-coverage" } }, "homepage": "https://github.com/commitizen/cz-cli", @@ -54,6 +55,10 @@ "babel-preset-stage-2": "6.17.0", "chai": "3.5.0", "codecov.io": "0.1.6", + "eslint": "3.12.2", + "eslint-config-standard": "6.2.1", + "eslint-plugin-promise": "3.4.0", + "eslint-plugin-standard": "2.0.1", "ghooks": "1.3.0", "in-publish": "^2.0.0", "mocha": "3.1.2", diff --git a/src/cli/git-cz.js b/src/cli/git-cz.js index 4dc38a21..fb633cf1 100644 --- a/src/cli/git-cz.js +++ b/src/cli/git-cz.js @@ -25,4 +25,4 @@ function bootstrap(environment = {}) { // This tells commitizen that it is not needed, just use git useGitStrategy(rawGitArgs, environment); } -} \ No newline at end of file +} diff --git a/src/cli/parsers.js b/src/cli/parsers.js index e9e2f568..beb6db64 100644 --- a/src/cli/parsers.js +++ b/src/cli/parsers.js @@ -4,4 +4,4 @@ import * as gitCz from './parsers/git-cz'; export { commitizen, gitCz -}; \ No newline at end of file +}; diff --git a/src/cli/parsers/commitizen.js b/src/cli/parsers/commitizen.js index 4befbe75..ec655125 100644 --- a/src/cli/parsers/commitizen.js +++ b/src/cli/parsers/commitizen.js @@ -18,4 +18,4 @@ function parse(rawGitArgs) { }); return args; -} \ No newline at end of file +} diff --git a/src/cli/parsers/git-cz.js b/src/cli/parsers/git-cz.js index 23d8075d..9c44b36f 100644 --- a/src/cli/parsers/git-cz.js +++ b/src/cli/parsers/git-cz.js @@ -25,7 +25,7 @@ function parse(rawGitArgs) { for (let arg in args) { if (!args.hasOwnProperty(arg)) { - //The current property is not a direct property + // The current property is not a direct property continue; } @@ -67,4 +67,4 @@ function parse(rawGitArgs) { } else { return output; } -} \ No newline at end of file +} diff --git a/src/cli/strategies.js b/src/cli/strategies.js index 59a7556f..3e6752b5 100644 --- a/src/cli/strategies.js +++ b/src/cli/strategies.js @@ -4,4 +4,4 @@ import gitCz from './strategies/git-cz'; export { git, gitCz -}; \ No newline at end of file +}; diff --git a/src/cli/strategies/git.js b/src/cli/strategies/git.js index 42f64a5b..1b59cf0f 100644 --- a/src/cli/strategies/git.js +++ b/src/cli/strategies/git.js @@ -1,4 +1,4 @@ -import child_process from 'child_process'; +import childProcess from 'child_process'; export default git; @@ -10,7 +10,7 @@ function git(rawGitArgs, environment) { } else { var vanillaGitArgs = ["commit"].concat(rawGitArgs); - var child = child_process.spawn('git', vanillaGitArgs, { + var child = childProcess.spawn('git', vanillaGitArgs, { stdio: 'inherit' }); diff --git a/src/commitizen.js b/src/commitizen.js index 35db43af..254ce4ba 100644 --- a/src/commitizen.js +++ b/src/commitizen.js @@ -12,4 +12,4 @@ export { configLoader, init, staging -}; \ No newline at end of file +}; diff --git a/src/commitizen/adapter.js b/src/commitizen/adapter.js index 129c3cff..00af7ee3 100644 --- a/src/commitizen/adapter.js +++ b/src/commitizen/adapter.js @@ -46,7 +46,7 @@ function addPathToAdapterConfig(sh, cliPath, repoPath, adapterNpmName) { let indent = detectIndent(packageJsonString).indent || ' '; let packageJsonContent = JSON.parse(packageJsonString); let newPackageJsonContent = ''; - if(_.get(packageJsonContent,'config.commitizen.path') !== adapterNpmName) { + if(_.get(packageJsonContent, 'config.commitizen.path') !== adapterNpmName) { newPackageJsonContent = _.merge(packageJsonContent, commitizenAdapterConfig); } fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJsonContent, null, indent) + '\n'); diff --git a/src/commitizen/cache.js b/src/commitizen/cache.js index ee2b0146..a83962fd 100644 --- a/src/commitizen/cache.js +++ b/src/commitizen/cache.js @@ -41,4 +41,4 @@ function getCacheValueSync(cachePath, repoPath) { } catch(e) { return; } -} \ No newline at end of file +} diff --git a/src/commitizen/configLoader.js b/src/commitizen/configLoader.js index f575198a..7946bfb7 100644 --- a/src/commitizen/configLoader.js +++ b/src/commitizen/configLoader.js @@ -7,4 +7,4 @@ var configs = ['package.json', '.czrc', '.cz.json']; function load(config, cwd) { return loader(configs, config, cwd); -} \ No newline at end of file +} diff --git a/src/commitizen/init.js b/src/commitizen/init.js index 4d8e4d82..6e88c409 100644 --- a/src/commitizen/init.js +++ b/src/commitizen/init.js @@ -128,4 +128,4 @@ function loadAdapterConfig() { } else { return; } -} \ No newline at end of file +} diff --git a/src/common/util.js b/src/common/util.js index 94f688fc..5dc4245c 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -78,7 +78,7 @@ function isString(str) { } else if (str === null) { return false; } else { - return Object.prototype.toString.call(str) == '[object String]'; + return Object.prototype.toString.call(str) === '[object String]'; } } diff --git a/src/configLoader.js b/src/configLoader.js index 36eaf18f..e11d5fe3 100644 --- a/src/configLoader.js +++ b/src/configLoader.js @@ -8,4 +8,4 @@ export { getContent, getNormalizedConfig, loader -}; \ No newline at end of file +}; diff --git a/src/configLoader/findup.js b/src/configLoader/findup.js index 0f2cb61b..a2972e2b 100644 --- a/src/configLoader/findup.js +++ b/src/configLoader/findup.js @@ -31,4 +31,4 @@ function findup(patterns, options, fn) { lastpath = options.cwd; options.cwd = path.resolve(options.cwd, '..'); } while (options.cwd !== lastpath); -} \ No newline at end of file +} diff --git a/src/configLoader/getNormalizedConfig.js b/src/configLoader/getNormalizedConfig.js index 96a10858..be00fe31 100644 --- a/src/configLoader/getNormalizedConfig.js +++ b/src/configLoader/getNormalizedConfig.js @@ -4,14 +4,14 @@ export default getNormalizedConfig; // settings that we're interested in function getNormalizedConfig(config, content) { - if(content && (config == 'package.json')) { + if(content && (config === 'package.json')) { // PACKAGE.JSON // Use the npm config key, be good citizens if(content.config && content.config.commitizen) { return content.config.commitizen; - } else if(content.czConfig) { // Old method, will be deprecated in 3.0.0 + } else if(content.czConfig) { // Old method, will be deprecated in 3.0.0 // Suppress during test if(typeof global.it !== 'function') @@ -25,4 +25,4 @@ function getNormalizedConfig(config, content) { return content; } -} \ No newline at end of file +} diff --git a/src/git.js b/src/git.js index 759b0691..3774acfd 100644 --- a/src/git.js +++ b/src/git.js @@ -8,4 +8,4 @@ export { commit, init, log -}; \ No newline at end of file +}; diff --git a/src/git/add.js b/src/git/add.js index 47f8ade6..58d94e10 100644 --- a/src/git/add.js +++ b/src/git/add.js @@ -6,4 +6,4 @@ export { addPath }; function addPath(sh, repoPath) { sh.cd(repoPath); sh.exec('git add .'); -} \ No newline at end of file +} diff --git a/src/git/log.js b/src/git/log.js index 45366a14..f8c39d9d 100644 --- a/src/git/log.js +++ b/src/git/log.js @@ -12,7 +12,6 @@ function log(repoPath, done) { }, function(error, stdout, stderr) { if (error) { throw error; - done(); } done(stdout); }); diff --git a/src/index.js b/src/index.js index 2168cc69..9a91d912 100644 --- a/src/index.js +++ b/src/index.js @@ -1,2 +1,2 @@ var commitizen = require('./commitizen'); -module.exports = commitizen; \ No newline at end of file +module.exports = commitizen; diff --git a/src/npm.js b/src/npm.js index c766030c..5e136acc 100644 --- a/src/npm.js +++ b/src/npm.js @@ -1 +1 @@ -// this file left blank until npm init is implemented \ No newline at end of file +// this file left blank until npm init is implemented diff --git a/test/config.js b/test/config.js index b598b164..02df0ada 100644 --- a/test/config.js +++ b/test/config.js @@ -62,4 +62,4 @@ let config = { preserve: 1 }; -export {config}; \ No newline at end of file +export {config}; diff --git a/test/tests/adapter.js b/test/tests/adapter.js index 966fcc62..29b71d7f 100644 --- a/test/tests/adapter.js +++ b/test/tests/adapter.js @@ -1,3 +1,5 @@ +/* eslint-env mocha */ + import {expect} from 'chai'; import path from 'path'; diff --git a/test/tests/cli.js b/test/tests/cli.js index 56373383..12ac5774 100644 --- a/test/tests/cli.js +++ b/test/tests/cli.js @@ -1,3 +1,5 @@ +/* eslint-env mocha */ + import {expect} from 'chai'; import proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -56,4 +58,4 @@ describe('git-cz', () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/test/tests/commit.js b/test/tests/commit.js index 10acd61d..9c2aa4b6 100644 --- a/test/tests/commit.js +++ b/test/tests/commit.js @@ -1,3 +1,5 @@ +/* eslint-env mocha */ + import {expect} from 'chai'; import fs from 'fs'; import os from 'os'; @@ -141,7 +143,7 @@ describe('commit', function() { some sizzurp`; - let dummyCommitMessage = (os.platform == 'win32') ? windowsCommitMessage : nixCommitMessage; + let dummyCommitMessage = (os.platform === 'win32') ? windowsCommitMessage : nixCommitMessage; // Describe a repo and some files to add and commit let repoConfig = { diff --git a/test/tests/configLoader.js b/test/tests/configLoader.js index 7cb13a88..1e135af2 100644 --- a/test/tests/configLoader.js +++ b/test/tests/configLoader.js @@ -1,3 +1,5 @@ +/* eslint-env mocha */ + import path from 'path'; import {expect} from 'chai'; import {getContent, getNormalizedConfig} from '../../src/configLoader'; diff --git a/test/tests/index.js b/test/tests/index.js index f6b2f176..77d4a5ce 100644 --- a/test/tests/index.js +++ b/test/tests/index.js @@ -4,4 +4,4 @@ import './commit'; import './configLoader'; import './init'; import './staging'; -import './util'; \ No newline at end of file +import './util'; diff --git a/test/tests/init.js b/test/tests/init.js index 5f1d808d..a1c34e75 100644 --- a/test/tests/init.js +++ b/test/tests/init.js @@ -1,3 +1,5 @@ +/* eslint-env mocha */ + import {expect} from 'chai'; import path from 'path'; import fs from 'fs'; @@ -79,8 +81,8 @@ describe('init', function() { // Check resulting json let packageJson = util.getParsedPackageJsonFromPath(config.paths.endUserRepo); - expect(packageJson).not.to.have.deep.property('devDependencies','cz-jira-smart-commit'); - expect(packageJson).to.have.deep.property('config.commitizen.path','./node_modules/cz-conventional-changelog'); + expect(packageJson).not.to.have.deep.property('devDependencies', 'cz-jira-smart-commit'); + expect(packageJson).to.have.deep.property('config.commitizen.path', './node_modules/cz-conventional-changelog'); // TODO: Eventually may need to offer both path and package keys. package = npm package name // Path for local development }); diff --git a/test/tests/staging.js b/test/tests/staging.js index a413216c..faf1cdf0 100644 --- a/test/tests/staging.js +++ b/test/tests/staging.js @@ -1,3 +1,5 @@ +/* eslint-env mocha */ + import {expect} from 'chai'; import path from 'path'; import fs from 'fs'; diff --git a/test/tests/util.js b/test/tests/util.js index 2d6e9ee8..8ead0ad2 100644 --- a/test/tests/util.js +++ b/test/tests/util.js @@ -1,3 +1,5 @@ +/* eslint-env mocha */ + import {expect} from 'chai'; import {isArray, isFunction, isString} from '../../src/common/util'; @@ -8,7 +10,9 @@ describe('common util', function() { // Truthies expect(isArray([])).to.be.true; expect(isArray([1, 2, 3])).to.be.true; + // eslint-disable-next-line no-sparse-arrays expect(isArray([1, , 3])).to.be.true; + // eslint-disable-next-line no-array-constructor expect(isArray(new Array())).to.be.true; // Falsies @@ -28,6 +32,7 @@ describe('common util', function() { // Truthies expect(isFunction(function(){})).to.be.true; + // eslint-disable-next-line no-new-func expect(isFunction(new Function())).to.be.true; // Falsies @@ -53,6 +58,7 @@ describe('common util', function() { line string` )).to.be.true; + // eslint-disable-next-line no-new-wrappers expect(isString(new String())).to.be.true; // Falsies @@ -67,4 +73,4 @@ describe('common util', function() { expect(isString(Symbol())).to.be.false; }); -}); \ No newline at end of file +}); diff --git a/test/tools/files.js b/test/tools/files.js index 2e50cadf..6fd830bd 100644 --- a/test/tools/files.js +++ b/test/tools/files.js @@ -17,4 +17,4 @@ function writeFilesToPath(files, directoryPath) { _.forOwn(files, function(key, value) { fs.writeFileSync(path.resolve(directoryPath, files[value].filename), files[value].contents); }); -} \ No newline at end of file +} diff --git a/test/tools/repo.js b/test/tools/repo.js index 4989ad77..04376795 100644 --- a/test/tools/repo.js +++ b/test/tools/repo.js @@ -17,4 +17,4 @@ function createEmpty(sh, path) { */ function createEndUser(sh, path) { createEmpty(sh, path); -} \ No newline at end of file +} diff --git a/test/tools/trigger-appveyor-tests.js b/test/tools/trigger-appveyor-tests.js index 344441e1..26aa5744 100644 --- a/test/tools/trigger-appveyor-tests.js +++ b/test/tools/trigger-appveyor-tests.js @@ -50,4 +50,4 @@ function ensureEnvironmentVariableIsSet(envName) { console.error('ERROR: The environment variable '+ envName + ' was not set and is required to run windows tests.'); process.exit(1); } -} \ No newline at end of file +}