Skip to content

fix: rebuff rules #34

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

Merged
merged 77 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
4768ca9
test: add test cases for footer-empty
marionebl May 1, 2017
5f9a618
fix: finish footer-empty implementation
marionebl May 1, 2017
cffc077
test: add test cases for footer-max-length
marionebl May 1, 2017
06fb33b
fix: allow empty footer for footer-max-length
marionebl May 1, 2017
380705b
test: correct non-criticals in footer-max-length tests
marionebl May 1, 2017
bd1e874
test: add test cases for footer-min-length
marionebl May 1, 2017
5d0b4e0
fix: allow empty footer for footer-min-length
marionebl May 1, 2017
419af1f
test: add cases for body-empty
marionebl May 1, 2017
ada66d0
fix: use keywords in body-empty
marionebl May 1, 2017
76efafa
test: add cases for subject-empty
marionebl May 1, 2017
89b9cb0
fix: use keywords in subject-empty
marionebl May 1, 2017
6194f4a
test: add cases for type-empty
marionebl May 1, 2017
4bebfc7
test: remove superfluous message prefixes
marionebl May 1, 2017
70e42f5
fix: use keywords in type-empty
marionebl May 1, 2017
d304cbf
style: move tests into colocation
marionebl May 1, 2017
6c338e0
test: add body-case test cases
marionebl May 4, 2017
65fc90a
fix: handle empty body gracefully
marionebl May 4, 2017
6b725ac
fix: rework ensure-case to produce saner output
marionebl May 4, 2017
1fdbdae
test: add cases for body-leading-blank
marionebl May 4, 2017
e314d5b
test: add multiline body cases for footer-leading-blank
marionebl May 4, 2017
ea74188
fix: handle multiline bodies properly
marionebl May 4, 2017
25c43f8
fix: harden body-leading-blank implementation
marionebl May 4, 2017
7dfc3a2
test: add body-max-length cases
marionebl May 4, 2017
5e7f0ef
fix: handle empty body gracefully
marionebl May 4, 2017
239b7a0
test: add body-min-length cases
marionebl May 4, 2017
d74210d
fix: handle empty body gracefully
marionebl May 4, 2017
6269cf3
fix: add test case for footer-tense
marionebl May 4, 2017
6113353
feat: introduce object based config for footer-tense
marionebl May 4, 2017
010aabf
test: add header length tests
marionebl May 4, 2017
6ca5e80
test: add case rule tests
marionebl May 4, 2017
bb3fe0d
fix: handle empty scope
marionebl May 4, 2017
0871f45
fix: handle empty subject
marionebl May 4, 2017
6ef3dc7
style: harmonize case rules
marionebl May 4, 2017
98e53f3
fix: handle empty type
marionebl May 4, 2017
b46c481
test: harmonize length tests
marionebl May 4, 2017
0cd5f50
test: add length tests
marionebl May 4, 2017
47dc14e
chore: be specific about ava test files
marionebl May 4, 2017
42a5545
fix: implement length checks correctly
marionebl May 4, 2017
5dabf9d
chore: update dev dependencies
marionebl May 6, 2017
05fcd76
test: add subject-full-stop cases
marionebl May 6, 2017
66cc1c5
fix: harden subject-full-stop implementation
marionebl May 6, 2017
c3e48c3
test: add case for subject-leading-capital
marionebl May 6, 2017
5e69f94
fix: harden subject-leading-capital
marionebl May 6, 2017
23ace19
test: add body-tense case
marionebl May 6, 2017
cc90734
fix: harden body-tense rule
marionebl May 6, 2017
79f6c0a
fix: harden subject-tense
marionebl May 6, 2017
11f4126
test: add export case
marionebl May 6, 2017
a0f948c
test: add case for lang
marionebl May 7, 2017
55505b9
chore: harden lang implementation
marionebl May 7, 2017
7549a74
chore: add missing devDependency
marionebl May 7, 2017
54ff336
chore: add nyc coverage
marionebl May 7, 2017
0b1ad3f
test: add case for type-enum
marionebl May 7, 2017
765f9df
fix: harden type-enum
marionebl May 7, 2017
b594061
test: add case for ensure-case
marionebl May 7, 2017
e681119
chore: bring linting up to speed
marionebl May 7, 2017
aec063a
style: be consistent with xo
marionebl May 7, 2017
1dbe6d9
test: add case for ensure-enum
marionebl May 8, 2017
85717e1
fix: harden ensure-enum
marionebl May 8, 2017
12db90e
test: add case for ensure-language
marionebl May 8, 2017
8107fc8
test: add case for ensure-max-length
marionebl May 8, 2017
3dde66c
test: add case for ensure-min-length
marionebl May 8, 2017
8b7c0c9
test: add case for ensure-not-empty
marionebl May 8, 2017
730b846
test: add case for ensure-tense
marionebl May 9, 2017
77fb57c
fix: harden ensure tense against type errors
marionebl Jul 6, 2017
aea421b
chore: fix babel build on win32 platforms
marionebl Jul 6, 2017
da2b6db
test: add test cases for execute-rule
marionebl Jul 6, 2017
2762921
fix: handle noop calls gracefully
marionebl Jul 6, 2017
e0719d9
test: add test cases for get-preset
marionebl Jul 6, 2017
a9dd020
test: add test cases for format
marionebl Jul 6, 2017
b3f2ca5
fix: more solid formatter implementation
marionebl Jul 6, 2017
0c6e275
test: add shell tests for parse method
marionebl Jul 6, 2017
b80fcf6
fix: solidify and test resolve-extends
marionebl Jul 7, 2017
2695c4e
test: execute color format test only if supported
marionebl Jul 7, 2017
7fb4b3a
fix: harmonize dynamic importers
marionebl Jul 7, 2017
7d04993
chore: cleanup
marionebl Jul 7, 2017
f4c9368
chore: do not babel test files
marionebl Jul 7, 2017
8136c14
chore: ignore *.test only for prod builds
marionebl Jul 7, 2017
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ node_modules

# transpiled artifacts
distribution

.nyc_output
3 changes: 0 additions & 3 deletions .jsonlintrc

This file was deleted.

63 changes: 57 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
},
"scripts": {
"start": "npm run watch",
"build": "babel source --out-dir distribution",
"build": "cross-env BABEL_ENV=production babel source --out-dir distribution",
"watch": "npm run build -- --watch",
"commit": "git-cz",
"commitmsg": "npm run build && node distribution/cli.js --edit",
"changelog": "conventional-changelog --preset angular --infile changelog.md --same-file --output-unreleased",
"push": "git push && git push --tags && hub release create \"v$npm_package_version\" --message=\"v$npm_package_version\n$(conventional-changelog -p angular)\" && npm publish",
"prepretest": "npm run lint",
"pretest": "npm run deps",
"test": "ava",
"lint": "xo *.js",
"test": "nyc ava -c=4",
"lint": "xo",
"deps": "npm run build && dependency-check . --missing && dependency-check . --extra --no-dev -i conventional-changelog-angular -i conventional-changelog-lint-config-angular",
"commitlint": "node distribution/cli.js --from=HEAD~1",
"preversion": "npm run build && npm test",
Expand All @@ -30,13 +30,40 @@
"travis:lint:commits": "./scripts/lint:commits.sh"
},
"ava": {
"files": [
"source/**/*.test.js",
"!distribution/**/*"
],
"source": [
"source/**/*.js",
"!distribution/**/*"
],
"babel": "inherit",
"require": [
"babel-register",
"babel-polyfill"
]
},
"babel": {
"env": {
"development": {
"sourceMaps": "inline",
"plugins": [
"add-module-exports",
"istanbul",
[
"transform-runtime",
{
"polyfill": false,
"regenerator": true
}
]
]
},
"production": {
"ignore": ["**/*.test.js"]
}
},
"presets": [
[
"env",
Expand All @@ -59,6 +86,22 @@
]
]
},
"nyc": {
"all": true,
"sourceMap": false,
"instrument": false,
"include": [
"source/**/*.js"
]
},
"xo": {
"plugins": [
"flow-check"
],
"rules": {
"flow-check/check": "error"
}
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog-lint"
Expand Down Expand Up @@ -89,24 +132,32 @@
},
"license": "MIT",
"devDependencies": {
"ansi-styles": "3.1.0",
"ava": "0.18.2",
"babel-cli": "6.18.0",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-istanbul": "4.1.3",
"babel-plugin-transform-runtime": "6.23.0",
"babel-polyfill": "6.20.0",
"babel-preset-env": "1.2.1",
"babel-preset-stage-0": "6.16.0",
"babel-register": "6.24.1",
"conventional-changelog-cli": "1.2.0",
"conventional-recommended-bump": "0.3.0",
"cross-env": "5.0.1",
"cz-conventional-changelog-lint": "0.1.3",
"denodeify": "1.2.1",
"dependency-check": "2.7.0",
"execa": "0.6.0",
"eslint-plugin-flow-check": "1.1.1",
"execa": "0.6.3",
"globby": "6.1.0",
"has-ansi": "3.0.0",
"import-from": "2.1.0",
"nyc": "10.3.2",
"path-exists": "3.0.0",
"resolve-from": "3.0.0",
"rimraf": "2.6.1",
"unexpected": "10.20.0",
"xo": "0.17.1"
"xo": "0.18.2"
},
"dependencies": {
"babel-polyfill": "6.20.0",
Expand Down
17 changes: 3 additions & 14 deletions source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import stdin from 'get-stdin';

import pkg from '../package.json'; // eslint-disable-line import/extensions
import help from './help';
import lint from './';
import {format, getConfiguration, getPreset, getMessages} from './'; // eslint-disable-line no-duplicate-imports
import lint, {format, getConfiguration, getPreset, getMessages} from './';

/**
* Behavioural rules
Expand All @@ -23,12 +22,8 @@ const rules = {
};

const configuration = {
// flags of string type
string: ['from', 'to', 'preset', 'extends'],
// flags of array type
// flags of bool type
boolean: ['edit', 'help', 'version', 'quiet', 'color'],
// flag aliases
alias: {
c: 'color',
e: 'edit',
Expand All @@ -41,15 +36,14 @@ const configuration = {
x: 'extends'
},
description: {
color: 'toggle formatted output',
color: 'toggle colored output',
edit: 'read last commit message found in ./git/COMMIT_EDITMSG',
extends: 'array of shareable configurations to extend',
from: 'lower end of the commit range to lint; applies if edit=false',
preset: 'conventional-changelog-preset to use for commit message parsing',
to: 'upper end of the commit range to lint; applies if edit=false',
quiet: 'toggle console output'
},
// flag defaults
default: {
color: true,
edit: false,
Expand All @@ -58,7 +52,6 @@ const configuration = {
to: null,
quiet: false
},
// fail on unknown
unknown(arg) {
throw new Error(`unknown flags: ${arg}`);
}
Expand Down Expand Up @@ -101,11 +94,7 @@ async function main(options) {
)
});

const formatted = format(report, {
color: flags.color,
signs: [' ', '⚠', '✖'],
colors: ['white', 'yellow', 'red']
});
const formatted = format(report, {color: flags.color});

if (!flags.quiet) {
console.log(`${fmt.grey('⧗')} input: ${fmt.bold(commit.split('\n')[0])}`);
Expand Down
13 changes: 4 additions & 9 deletions source/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {merge} from 'lodash';

import ruleFunctions from './rules';
import format from './library/format';
import getConfiguration from './library/get-configuration';
Expand All @@ -11,19 +9,16 @@ export {format, getConfiguration, getMessages, getPreset};

export default async (message, options = {}) => {
const {
preset: {
parserOpts: parserOptions
},
configuration: {
rules,
wildcards
}
} = options;

// parse the commit message
// Parse the commit message
const parsed = parse(message);

// wildcard matches skip the linting
// Wildcard matches skip the linting
const bails = Object.entries(wildcards)
.filter(entry => {
const [, pattern] = entry;
Expand All @@ -36,7 +31,7 @@ export default async (message, options = {}) => {
})
.map(entry => entry[0]);

// found a wildcard match, skip
// Found a wildcard match, skip
if (bails.length > 0) {
return {
valid: true,
Expand All @@ -47,7 +42,7 @@ export default async (message, options = {}) => {
};
}

// validate against all rules
// Validate against all rules
const results = Object.entries(rules)
.filter(entry => {
const [, [level]] = entry;
Expand Down
13 changes: 10 additions & 3 deletions source/library/ensure-case.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export default (a, stringCase) => {
const method = `to${stringCase[0].toUpperCase()}${stringCase.slice(1)}`;
return typeof a !== 'string' || a[method]() === a;
export default (raw = '', target = 'lowercase') => {
const normalized = String(raw);

switch (target) {
case 'uppercase':
return normalized.toUpperCase() === normalized;
case 'lowercase':
default:
return normalized.toLowerCase() === normalized;
}
};
42 changes: 42 additions & 0 deletions source/library/ensure-case.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import test from 'ava';
import ensure from './ensure-case';

test('true for no params', t => {
const actual = ensure();
t.is(actual, true);
});

test('true for empty', t => {
const actual = ensure('');
t.is(actual, true);
});

test('true for lowercase', t => {
const actual = ensure('a');
t.is(actual, true);
});

test('false for uppercase', t => {
const actual = ensure('A');
t.is(actual, false);
});

test('true for lowercase on lowercase', t => {
const actual = ensure('a', 'lowercase');
t.is(actual, true);
});

test('false for uppercase on lowercase', t => {
const actual = ensure('A', 'lowercase');
t.is(actual, false);
});

test('true for uppercase on uppercase', t => {
const actual = ensure('A', 'uppercase');
t.is(actual, true);
});

test('false for lowercase on lowercase', t => {
const actual = ensure('a', 'uppercase');
t.is(actual, false);
});
8 changes: 7 additions & 1 deletion source/library/ensure-enum.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export default (value, enums) => {
export default (value, enums = []) => {
if (value === undefined) {
return false;
}
if (!Array.isArray(enums)) {
return false;
}
return enums.indexOf(value) > -1;
};
42 changes: 42 additions & 0 deletions source/library/ensure-enum.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import test from 'ava';
import ensure from './ensure-enum';

test('false for no params', t => {
const actual = ensure();
t.is(actual, false);
});

test('true for a against a', t => {
const actual = ensure('a', ['a']);
t.is(actual, true);
});

test('false for a against b', t => {
const actual = ensure('a', ['b']);
t.is(actual, false);
});

test('true for a against a, b', t => {
const actual = ensure('a', ['a', 'b']);
t.is(actual, true);
});

test('false for b against a', t => {
const actual = ensure('b', ['a']);
t.is(actual, false);
});

test('true for b against b', t => {
const actual = ensure('b', ['b']);
t.is(actual, true);
});

test('true for b against a, b', t => {
const actual = ensure('b', ['a', 'b']);
t.is(actual, true);
});

test('false for c against a, b', t => {
const actual = ensure('c', ['a', 'b']);
t.is(actual, false);
});
5 changes: 3 additions & 2 deletions source/library/ensure-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import franc from 'franc';
export default (input, allowed) => {
const detected = franc.all(input)
.filter(lang => lang[1] >= 0.45)
.map(lang => lang[0]);
.map(lang => lang[0])
.slice(0, 5);

// franc spits out ['und'] when unable to
// Library franc spits out ['und'] when unable to
// guess any languages, let it through in this case
const matches = detected[0] === 'und' ||
detected.indexOf(allowed) > -1;
Expand Down
Loading