commitplease
Advanced tools
Comparing version 1.11.0 to 2.0.0
var merge = require( "mout/object/merge" ), | ||
semver = require( "semver"), | ||
subjectExceptions = /^(fixup|squash)!|^\[[^\]]+\]:/, | ||
defaults = { | ||
@@ -36,15 +37,17 @@ component: true, | ||
if ( options.component && line.indexOf( ":" ) < 1 ) { | ||
errors.push( "First line (subject) must indicate the component" ); | ||
if ( !subjectExceptions.test( line ) ) { | ||
if ( options.component && line.indexOf( ":" ) < 1 ) { | ||
errors.push( "First line (subject) must indicate the component" ); | ||
} | ||
var matchedComponent = line.replace( /:.+/, "" ); | ||
if ( options.components.length && matchedComponent && | ||
options.components.indexOf( matchedComponent ) === -1 ) { | ||
errors.push( "Component invalid, was '" + matchedComponent + | ||
"', must be one of these: " + options.components.join( ", " ) ); | ||
} | ||
if ( options.component && line.substring( line.indexOf( ":" ) + 1 ).length < 1 ) { | ||
errors.push( "First line (subject) must have a message after the component" ); | ||
} | ||
} | ||
var matchedComponent = line.replace( /:.+/, "" ); | ||
if ( options.components.length && matchedComponent && | ||
options.components.indexOf( matchedComponent ) === -1 ) { | ||
errors.push( "Component invalid, was '" + matchedComponent + | ||
"', must be one of these: " + options.components.join( ", " ) ); | ||
} | ||
if ( options.component && line.substring( line.indexOf( ":" ) + 1 ).length < 1 ) { | ||
errors.push( "First line (subject) must have a message after the component" ); | ||
} | ||
} | ||
@@ -51,0 +54,0 @@ if ( index === 1 && line.length > 0 ) { |
{ | ||
"name": "commitplease", | ||
"version": "1.11.0", | ||
"version": "2.0.0", | ||
"description": "Validates strings as commit messages", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"uninstall": "node uninstall", | ||
"test": "nodeunit test.js" | ||
"test": "jshint lib/ *.js && jscs lib/ *.js && nodeunit test.js" | ||
}, | ||
@@ -27,3 +27,5 @@ "repository": { | ||
"devDependencies": { | ||
"nodeunit": "0.8.2" | ||
"nodeunit": "0.8.2", | ||
"jshint": "2.5.6", | ||
"jscs": "1.7.3" | ||
}, | ||
@@ -30,0 +32,0 @@ "dependencies": { |
@@ -19,2 +19,6 @@ # Commitplease | ||
By default, the commit message needs to match the [jQuery Commit Guidlines](http://contribute.jquery.org/commits-and-pull-requests/#commit-guidelines). See there for details, and below on how to change the default behaviour. | ||
In addition, a subject (the first line) starting with "fixup!" and "squash!" is considered valid. These are generated by `git commit --fixup` and `--squash`. A component in square brackets like "[Tmp]" or "[fix]" is also considered valid, to be manually squashed later. | ||
## API | ||
@@ -21,0 +25,0 @@ |
22
setup.js
(function avoidSelfInstall() { | ||
var pkg = require('./package'), | ||
nameRegex = new RegExp('node_modules/' + pkg.name + '$'); | ||
if (!nameRegex.test(process.cwd().replace(/\\/g, '/'))) { | ||
console.log('running install inside self, no need'); | ||
var pkg = require("./package"), | ||
nameRegex = new RegExp("node_modules/" + pkg.name + "$"); | ||
if (!nameRegex.test(process.cwd().replace(/\\/g, "/"))) { | ||
console.log("running install inside self, no need"); | ||
process.exit(0); | ||
@@ -10,11 +10,11 @@ } | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var root = path.resolve(__dirname, '../..'); | ||
var git = path.resolve(root, '.git'); | ||
var hooks = path.resolve(git, 'hooks'); | ||
var path = require("path"); | ||
var fs = require("fs"); | ||
var root = path.resolve(__dirname, "../.."); | ||
var git = path.resolve(root, ".git"); | ||
var hooks = path.resolve(git, "hooks"); | ||
// Check if we are in a git repository so we can bail out early when this is not the case. | ||
if (!fs.existsSync(git) || !fs.lstatSync(git).isDirectory()) { | ||
console.error('Could not find git repo in ' + git); | ||
console.error("Could not find git repo in " + git); | ||
process.exit(0); | ||
@@ -36,3 +36,3 @@ } | ||
fs.chmodSync( hook, "755" ); | ||
} catch(e) { | ||
} catch (e) { | ||
if (/EPERM/.test(e.message)) { | ||
@@ -39,0 +39,0 @@ console.error( "Failed to write commit-msg hook. " + |
33
test.js
@@ -6,3 +6,3 @@ var validate = require( "./lib/validate" ), | ||
"\n" + | ||
"Long description" | ||
"Long description"; | ||
@@ -22,4 +22,8 @@ var messageWithDiff = "Component: short message\n" + | ||
"- \n" + | ||
"+ }, mment that has to be ignored line too long beyond 72 chars line too long beyond" | ||
"+ }, mment that has to be ignored line too long beyond 72 chars line too long beyond"; | ||
var testComponent = { | ||
components: [ "Test" ] | ||
}; | ||
var valid = [ | ||
@@ -93,2 +97,18 @@ { | ||
msg: "Merge branch 'one' into two" | ||
}, | ||
{ | ||
msg: "fixup! for git to squash", | ||
options: testComponent | ||
}, | ||
{ | ||
msg: "squash! for git to squish", | ||
options: testComponent | ||
}, | ||
{ | ||
msg: "[fix]: whatever fix", | ||
options: testComponent | ||
}, | ||
{ | ||
msg: "[Tmp]: do this and that", | ||
options: testComponent | ||
} | ||
@@ -114,3 +134,7 @@ ]; | ||
msg: "", | ||
expected: [ "First line (subject) must not be empty", "First line (subject) must indicate the component", "First line (subject) must have a message after the component" ] | ||
expected: [ | ||
"First line (subject) must not be empty", | ||
"First line (subject) must indicate the component", | ||
"First line (subject) must have a message after the component" | ||
] | ||
}, | ||
@@ -155,4 +179,3 @@ { | ||
{ | ||
msg: "bla: blu\n\n# comment\nResolving xy12312312312" | ||
, | ||
msg: "bla: blu\n\n# comment\nResolving xy12312312312", | ||
expected: [ "Invalid ticket reference, must be /(Fixes|Closes) (.*#|gh-)[0-9]+/, was: Resolving xy12312312312" ] | ||
@@ -159,0 +182,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
14690
14
358
82
3