@commitlint/cli
Advanced tools
Comparing version
export declare class CliError extends Error { | ||
__proto__: ErrorConstructor; | ||
type: string; | ||
constructor(message: string, type: string); | ||
error_code: number; | ||
constructor(message: string, type: string, error_code?: number); | ||
} | ||
//# sourceMappingURL=cli-error.d.ts.map |
@@ -5,6 +5,7 @@ "use strict"; | ||
class CliError extends Error { | ||
constructor(message, type) { | ||
constructor(message, type, error_code = 1) { | ||
super(message); | ||
this.__proto__ = Error; | ||
this.type = type; | ||
this.error_code = error_code; | ||
Object.setPrototypeOf(this, CliError.prototype); | ||
@@ -11,0 +12,0 @@ } |
@@ -13,6 +13,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const execa_1 = __importDefault(require("execa")); | ||
const load_1 = __importDefault(require("@commitlint/load")); | ||
const lint_1 = __importDefault(require("@commitlint/lint")); | ||
const read_1 = __importDefault(require("@commitlint/read")); | ||
const isFunction_1 = __importDefault(require("lodash/isFunction")); | ||
const lodash_isfunction_1 = __importDefault(require("lodash.isfunction")); | ||
const resolve_from_1 = __importDefault(require("resolve-from")); | ||
@@ -24,2 +25,3 @@ const resolve_global_1 = __importDefault(require("resolve-global")); | ||
const pkg = require('../package'); | ||
const gitDefaultCommentChar = '#'; | ||
const cli = yargs_1.default | ||
@@ -75,2 +77,6 @@ .options({ | ||
}, | ||
'git-log-args': { | ||
description: "additional git log arguments as space separated string, example '--first-parent --cherry-pick'", | ||
type: 'string', | ||
}, | ||
format: { | ||
@@ -102,2 +108,7 @@ alias: 'o', | ||
}, | ||
strict: { | ||
alias: 's', | ||
type: 'boolean', | ||
description: 'enable strict mode; result code 2 for warnings, 3 for errors', | ||
}, | ||
}) | ||
@@ -114,3 +125,3 @@ .version('version', 'display version information', `${pkg.name}@${pkg.version}`) | ||
if (err.type === pkg.name) { | ||
process.exit(1); | ||
process.exit(err.error_code); | ||
} | ||
@@ -121,3 +132,3 @@ throw err; | ||
async function stdin() { | ||
var e_1, _a; | ||
var _a, e_1, _b, _c; | ||
let result = ''; | ||
@@ -129,4 +140,6 @@ if (process.stdin.isTTY) { | ||
try { | ||
for (var _b = __asyncValues(process.stdin), _c; _c = await _b.next(), !_c.done;) { | ||
const chunk = _c.value; | ||
for (var _d = true, _e = __asyncValues(process.stdin), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) { | ||
_c = _f.value; | ||
_d = false; | ||
const chunk = _c; | ||
result += chunk; | ||
@@ -138,3 +151,3 @@ } | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b); | ||
if (!_d && !_a && (_b = _e.return)) await _b.call(_e); | ||
} | ||
@@ -172,2 +185,3 @@ finally { if (e_1) throw e_1.error; } | ||
cwd: flags.cwd, | ||
gitLogArgs: flags['git-log-args'], | ||
})); | ||
@@ -208,7 +222,18 @@ const messages = (Array.isArray(input) ? input : [input]) | ||
const format = loadFormatter(loaded, flags); | ||
// Strip comments if reading from `.git/COMMIT_EDIT_MSG` using the | ||
// commentChar from the parser preset falling back to a `#` if that is not | ||
// set | ||
if (flags.edit && typeof opts.parserOpts.commentChar !== 'string') { | ||
opts.parserOpts.commentChar = '#'; | ||
// If reading from `.git/COMMIT_EDIT_MSG`, strip comments using | ||
// core.commentChar from git configuration, falling back to '#'. | ||
if (flags.edit) { | ||
try { | ||
const { stdout } = await (0, execa_1.default)('git', ['config', 'core.commentChar']); | ||
opts.parserOpts.commentChar = stdout.trim() || gitDefaultCommentChar; | ||
} | ||
catch (e) { | ||
const execaError = e; | ||
// git config returns exit code 1 when the setting is unset, | ||
// don't warn in this case. | ||
if (!execaError.failed || execaError.exitCode !== 1) { | ||
console.warn('Could not determine core.commentChar git configuration', e); | ||
} | ||
opts.parserOpts.commentChar = gitDefaultCommentChar; | ||
} | ||
} | ||
@@ -230,4 +255,4 @@ const results = await Promise.all(messages.map((message) => (0, lint_1.default)(message, loaded.rules, opts))); | ||
'Please add rules to your `commitlint.config.js`', | ||
' - Getting started guide: https://git.io/fhHij', | ||
' - Example config: https://git.io/fhHip', | ||
' - Getting started guide: https://commitlint.js.org/#/?id=getting-started', | ||
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js', | ||
].join('\n'), | ||
@@ -261,2 +286,10 @@ }, | ||
} | ||
if (flags.strict) { | ||
if (report.errorCount > 0) { | ||
throw new cli_error_1.CliError(output, pkg.name, 3); | ||
} | ||
if (report.warningCount > 0) { | ||
throw new cli_error_1.CliError(output, pkg.name, 2); | ||
} | ||
} | ||
if (!report.valid) { | ||
@@ -340,3 +373,3 @@ throw new cli_error_1.CliError(output, pkg.name); | ||
const moduleInstance = require(modulePath); | ||
if ((0, isFunction_1.default)(moduleInstance.default)) { | ||
if ((0, lodash_isfunction_1.default)(moduleInstance.default)) { | ||
return moduleInstance.default; | ||
@@ -343,0 +376,0 @@ } |
@@ -11,2 +11,3 @@ export interface CliFlags { | ||
from?: string; | ||
'git-log-args'?: string; | ||
format?: string; | ||
@@ -19,9 +20,6 @@ 'parser-preset'?: string; | ||
'print-config'?: boolean; | ||
strict?: boolean; | ||
_: (string | number)[]; | ||
$0: string; | ||
} | ||
export interface Seed { | ||
extends?: string[]; | ||
parserPreset?: string; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@commitlint/cli", | ||
"version": "13.2.1", | ||
"version": "18.4.3", | ||
"description": "Lint your commit messages", | ||
@@ -18,7 +18,8 @@ "files": [ | ||
"engines": { | ||
"node": ">=v12" | ||
"node": ">=v18" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/conventional-changelog/commitlint.git" | ||
"url": "https://github.com/conventional-changelog/commitlint.git", | ||
"directory": "@commitlint/cli" | ||
}, | ||
@@ -28,3 +29,3 @@ "bugs": { | ||
}, | ||
"homepage": "https://github.com/conventional-changelog/commitlint#readme", | ||
"homepage": "https://commitlint.js.org/", | ||
"keywords": [ | ||
@@ -41,16 +42,19 @@ "conventional-changelog", | ||
"devDependencies": { | ||
"@commitlint/test": "^13.2.0", | ||
"@commitlint/utils": "^13.2.0", | ||
"@types/node": "12.20.28", | ||
"@types/yargs": "^17.0.0", | ||
"execa": "^5.0.0", | ||
"fs-extra": "^10.0.0" | ||
"@commitlint/test": "^18.0.0", | ||
"@commitlint/utils": "^18.4.3", | ||
"@types/lodash.isfunction": "^3.0.8", | ||
"@types/lodash.merge": "^4.6.8", | ||
"@types/node": "^18.11.9", | ||
"@types/yargs": "^17.0.29", | ||
"fs-extra": "^11.0.0", | ||
"lodash.merge": "^4.6.2" | ||
}, | ||
"dependencies": { | ||
"@commitlint/format": "^13.2.0", | ||
"@commitlint/lint": "^13.2.0", | ||
"@commitlint/load": "^13.2.1", | ||
"@commitlint/read": "^13.2.0", | ||
"@commitlint/types": "^13.2.0", | ||
"lodash": "^4.17.19", | ||
"@commitlint/format": "^18.4.3", | ||
"@commitlint/lint": "^18.4.3", | ||
"@commitlint/load": "^18.4.3", | ||
"@commitlint/read": "^18.4.3", | ||
"@commitlint/types": "^18.4.3", | ||
"execa": "^5.0.0", | ||
"lodash.isfunction": "^3.0.9", | ||
"resolve-from": "5.0.0", | ||
@@ -60,3 +64,3 @@ "resolve-global": "1.0.0", | ||
}, | ||
"gitHead": "b2a552a9693cb27dd291f61ea736e0dd5c02a20f" | ||
"gitHead": "970b806bdd338e8b3e4529f21f20e795e66cd48f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
420
8.53%30089
-43.06%10
11.11%8
33.33%17
-5.56%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated