Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting using eslint #406

Merged
merged 3 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ before_script:
- npm prune
- git version
script:
# Only run linting on Node.js 4.x and up
- if [ $(node -pe 'process.version.match(/v(\d+)\./)[1] >= 4') == 'true' ]; then npm run lint; fi
- npm run test
- npm run check-coverage
after_success:
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/git-cz.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ function bootstrap(environment = {}) {
// This tells commitizen that it is not needed, just use git
useGitStrategy(rawGitArgs, environment);
}
}
}
2 changes: 1 addition & 1 deletion src/cli/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import * as gitCz from './parsers/git-cz';
export {
commitizen,
gitCz
};
};
2 changes: 1 addition & 1 deletion src/cli/parsers/commitizen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ function parse(rawGitArgs) {
});

return args;
}
}
4 changes: 2 additions & 2 deletions src/cli/parsers/git-cz.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -67,4 +67,4 @@ function parse(rawGitArgs) {
} else {
return output;
}
}
}
2 changes: 1 addition & 1 deletion src/cli/strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import gitCz from './strategies/git-cz';
export {
git,
gitCz
};
};
4 changes: 2 additions & 2 deletions src/cli/strategies/git.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import child_process from 'child_process';
import childProcess from 'child_process';

export default git;

Expand All @@ -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'
});

Expand Down
2 changes: 1 addition & 1 deletion src/commitizen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export {
configLoader,
init,
staging
};
};
4 changes: 2 additions & 2 deletions src/commitizen/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -139,7 +139,7 @@ function resolveAdapterPath(inboundAdapterPath) {
// try to resolve the given path
return require.resolve(absoluteAdapterPath);
} catch (error) {
error.message = "Could not resolve " + absoluteAdapterPath, ". " + error.message;
error.message = "Could not resolve " + absoluteAdapterPath + ". " + error.message;
throw error;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commitizen/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ function getCacheValueSync(cachePath, repoPath) {
} catch(e) {
return;
}
}
}
2 changes: 1 addition & 1 deletion src/commitizen/configLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ var configs = ['package.json', '.czrc', '.cz.json'];

function load(config, cwd) {
return loader(configs, config, cwd);
}
}
2 changes: 1 addition & 1 deletion src/commitizen/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ function loadAdapterConfig() {
} else {
return;
}
}
}
2 changes: 1 addition & 1 deletion src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]';
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/configLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export {
getContent,
getNormalizedConfig,
loader
};
};
2 changes: 1 addition & 1 deletion src/configLoader/findup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ function findup(patterns, options, fn) {
lastpath = options.cwd;
options.cwd = path.resolve(options.cwd, '..');
} while (options.cwd !== lastpath);
}
}
6 changes: 3 additions & 3 deletions src/configLoader/getNormalizedConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -25,4 +25,4 @@ function getNormalizedConfig(config, content) {
return content;
}

}
}
2 changes: 1 addition & 1 deletion src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export {
commit,
init,
log
};
};
2 changes: 1 addition & 1 deletion src/git/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export { addPath };
function addPath(sh, repoPath) {
sh.cd(repoPath);
sh.exec('git add .');
}
}
1 change: 0 additions & 1 deletion src/git/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function log(repoPath, done) {
}, function(error, stdout, stderr) {
if (error) {
throw error;
done();
}
done(stdout);
});
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var commitizen = require('./commitizen');
module.exports = commitizen;
module.exports = commitizen;
2 changes: 1 addition & 1 deletion src/npm.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// this file left blank until npm init is implemented
// this file left blank until npm init is implemented
2 changes: 2 additions & 0 deletions test/tests/adapter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import {expect} from 'chai';
import path from 'path';

Expand Down
4 changes: 3 additions & 1 deletion test/tests/cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import {expect} from 'chai';
import proxyquire from 'proxyquire';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -56,4 +58,4 @@ describe('git-cz', () => {
});
});
});
});
});
4 changes: 3 additions & 1 deletion test/tests/commit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import {expect} from 'chai';
import fs from 'fs';
import os from 'os';
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions test/tests/configLoader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import path from 'path';
import {expect} from 'chai';
import {getContent, getNormalizedConfig} from '../../src/configLoader';
Expand Down
2 changes: 1 addition & 1 deletion test/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import './commit';
import './configLoader';
import './init';
import './staging';
import './util';
import './util';
6 changes: 4 additions & 2 deletions test/tests/init.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import {expect} from 'chai';
import path from 'path';
import fs from 'fs';
Expand Down Expand Up @@ -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
});
Expand Down
2 changes: 2 additions & 0 deletions test/tests/staging.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import {expect} from 'chai';
import path from 'path';
import fs from 'fs';
Expand Down
8 changes: 7 additions & 1 deletion test/tests/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env mocha */

import {expect} from 'chai';
import {isArray, isFunction, isString} from '../../src/common/util';

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -67,4 +73,4 @@ describe('common util', function() {
expect(isString(Symbol())).to.be.false;

});
});
});
2 changes: 1 addition & 1 deletion test/tools/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ function writeFilesToPath(files, directoryPath) {
_.forOwn(files, function(key, value) {
fs.writeFileSync(path.resolve(directoryPath, files[value].filename), files[value].contents);
});
}
}
2 changes: 1 addition & 1 deletion test/tools/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ function createEmpty(sh, path) {
*/
function createEndUser(sh, path) {
createEmpty(sh, path);
}
}
2 changes: 1 addition & 1 deletion test/tools/trigger-appveyor-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}