From 10de48ba91bf1d8ff6e523398085c5c4762e83fc Mon Sep 17 00:00:00 2001 From: escapedcat Date: Sun, 12 Jul 2020 16:39:26 +0800 Subject: [PATCH 1/2] chore: merge armanos branch --- @commitlint/cli/cli.js | 2 + @commitlint/cli/index.js | 2 +- @commitlint/cli/package.json | 62 +++- @commitlint/cli/src/cli-error.ts | 13 + .../cli/src/{cli.test.js => cli.test.ts} | 56 +++- @commitlint/cli/src/{cli.js => cli.ts} | 297 +++++++++--------- @commitlint/cli/src/help.js | 34 -- @commitlint/cli/src/types.ts | 24 ++ @commitlint/cli/tsconfig.json | 10 + @commitlint/format/package.json | 9 + @commitlint/format/src/format.ts | 38 +-- @commitlint/format/tsconfig.json | 3 +- @commitlint/lint/src/lint.test.ts | 4 +- @commitlint/lint/src/lint.ts | 34 +- @commitlint/types/src/format.ts | 37 +++ @commitlint/types/src/index.ts | 1 + @commitlint/types/src/lint.ts | 7 +- @commitlint/types/src/load.ts | 86 +---- @commitlint/types/src/rules.ts | 113 ++++++- docs/reference-cli.md | 40 ++- tsconfig.json | 3 +- yarn.lock | 54 ++-- 22 files changed, 562 insertions(+), 367 deletions(-) create mode 100755 @commitlint/cli/cli.js create mode 100644 @commitlint/cli/src/cli-error.ts rename @commitlint/cli/src/{cli.test.js => cli.test.ts} (84%) rename @commitlint/cli/src/{cli.js => cli.ts} (58%) mode change 100755 => 100644 delete mode 100644 @commitlint/cli/src/help.js create mode 100644 @commitlint/cli/src/types.ts create mode 100644 @commitlint/cli/tsconfig.json create mode 100644 @commitlint/types/src/format.ts diff --git a/@commitlint/cli/cli.js b/@commitlint/cli/cli.js new file mode 100755 index 0000000000..4856fd706c --- /dev/null +++ b/@commitlint/cli/cli.js @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('./lib/cli.js'); diff --git a/@commitlint/cli/index.js b/@commitlint/cli/index.js index 6babb12a58..bc56366369 100644 --- a/@commitlint/cli/index.js +++ b/@commitlint/cli/index.js @@ -1,3 +1,3 @@ const path = require('path'); -module.exports = path.join(__dirname, 'lib/cli.js'); +module.exports = path.join(__dirname, 'cli.js'); diff --git a/@commitlint/cli/package.json b/@commitlint/cli/package.json index 1931bbff4d..a35d1fb28c 100644 --- a/@commitlint/cli/package.json +++ b/@commitlint/cli/package.json @@ -4,26 +4,15 @@ "description": "Lint your commit messages", "files": [ "index.js", - "lib", - "!*.test.js*" + "cli.js", + "lib" ], "bin": { - "commitlint": "./lib/cli.js" + "commitlint": "./cli.js" }, "scripts": { - "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", "deps": "dep-check", - "pkg": "pkg-check", - "start": "yarn run watch", - "watch": "babel src --out-dir lib --watch --source-maps" - }, - "babel": { - "presets": [ - "babel-preset-commitlint" - ], - "ignore": [ - "**/*.test.js" - ] + "pkg": "pkg-check" }, "engines": { "node": ">=v8.17.0" @@ -47,16 +36,30 @@ }, "license": "MIT", "devDependencies": { +<<<<<<< HEAD "@babel/cli": "^7.7.7", "@babel/core": "^7.7.7", "@commitlint/test": "^9.1.1", "@commitlint/utils": "^9.1.1", "babel-preset-commitlint": "^9.1.1", "cross-env": "7.0.2", +||||||| f74e036 + "@babel/cli": "^7.7.7", + "@babel/core": "^7.7.7", + "@commitlint/test": "8.2.0", + "@commitlint/utils": "^8.3.4", + "babel-preset-commitlint": "^8.2.0", + "cross-env": "7.0.0", +======= + "@types/yargs": "^15.0.3", + "@commitlint/test": "8.2.0", + "@commitlint/utils": "^8.3.4", +>>>>>>> armano2/refactor-cli "execa": "^3.4.0", "fs-extra": "^8.1.0" }, "dependencies": { +<<<<<<< HEAD "@babel/runtime": "^7.9.6", "@commitlint/format": "^9.1.1", "@commitlint/lint": "^9.1.1", @@ -64,12 +67,41 @@ "@commitlint/read": "^9.1.1", "chalk": "4.1.0", "core-js": "^3.6.1", +||||||| f74e036 + "@commitlint/format": "^8.3.4", + "@commitlint/lint": "^8.3.5", + "@commitlint/load": "^8.3.5", + "@commitlint/read": "^8.3.4", + "chalk": "3.0.0", + "core-js": "^3.6.1", +======= + "@commitlint/format": "^8.3.4", + "@commitlint/lint": "^8.3.5", + "@commitlint/load": "^8.3.5", + "@commitlint/read": "^8.3.4", + "chalk": "3.0.0", +>>>>>>> armano2/refactor-cli "get-stdin": "7.0.0", "lodash": "^4.17.15", +<<<<<<< HEAD "meow": "5.0.0", "regenerator-runtime": "0.13.5", +||||||| f74e036 + "meow": "5.0.0", + "regenerator-runtime": "0.13.3", +======= +>>>>>>> armano2/refactor-cli "resolve-from": "5.0.0", +<<<<<<< HEAD "resolve-global": "1.0.0" }, "gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca" +||||||| f74e036 + "resolve-global": "1.0.0" + } +======= + "resolve-global": "1.0.0", + "yargs": "^15.1.0" + } +>>>>>>> armano2/refactor-cli } diff --git a/@commitlint/cli/src/cli-error.ts b/@commitlint/cli/src/cli-error.ts new file mode 100644 index 0000000000..757814a1ed --- /dev/null +++ b/@commitlint/cli/src/cli-error.ts @@ -0,0 +1,13 @@ +export class CliError extends Error { + __proto__ = Error; + + public type: string; + + constructor(message: string, type: string) { + super(message); + + this.type = type; + + Object.setPrototypeOf(this, CliError.prototype); + } +} diff --git a/@commitlint/cli/src/cli.test.js b/@commitlint/cli/src/cli.test.ts similarity index 84% rename from @commitlint/cli/src/cli.test.js rename to @commitlint/cli/src/cli.test.ts index 53d6258a90..0ab9c60560 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.ts @@ -4,9 +4,14 @@ import execa from 'execa'; import merge from 'lodash/merge'; import fs from 'fs-extra'; -const bin = require.resolve('../lib/cli.js'); +const bin = require.resolve('../cli.js'); -const cli = (args, options) => { +interface TestOptions { + cwd: string; + env?: Record; +} + +const cli = (args: string[], options: TestOptions) => { return (input = '') => { return execa(bin, args, { cwd: options.cwd, @@ -17,8 +22,8 @@ const cli = (args, options) => { }; }; -const gitBootstrap = fixture => git.bootstrap(fixture, __dirname); -const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname); +const gitBootstrap = (fixture: string) => git.bootstrap(fixture, __dirname); +const fixBootstrap = (fixture: string) => fix.bootstrap(fixture, __dirname); test('should throw when called without [input]', async () => { const cwd = await gitBootstrap('fixtures/default'); @@ -423,7 +428,48 @@ test('should work with relative formatter path', async () => { expect(actual.exitCode).toBe(0); }); -async function writePkg(payload, options) { +test('should print help', async () => { + const cwd = await gitBootstrap('fixtures/default'); + const actual = await cli(['--help'], {cwd})(); + expect(actual.stdout).toMatchInlineSnapshot(` + "@commitlint/cli@8.3.5 - Lint your commit messages + + [input] reads from stdin if --edit, --env, --from and --to are omitted + + Options: + --color, -c toggle colored output [boolean] [default: true] + --config, -g path to the config file [string] + --cwd, -d directory to execute in + [string] [default: (Working Directory)] + --edit, -e read last commit message from the specified file or + fallbacks to ./.git/COMMIT_EDITMSG + [string] [default: false] + --env, -E check message in the file at path given by environment + variable value [string] + --extends, -x array of shareable configurations to extend [array] + --help-url, -H help url in error message [string] + --from, -f lower end of the commit range to lint; applies if + edit=false [string] + --format, -o output format of the results [string] + --parser-preset, -p configuration preset to use for + conventional-commits-parser [string] + --quiet, -q toggle console output [boolean] [default: false] + --to, -t upper end of the commit range to lint; applies if + edit=false [string] + --verbose, -V enable verbose output for reports without problems + [boolean] + -v, --version display version information [boolean] + -h, --help Show help [boolean]" + `); +}); + +test('should print version', async () => { + const cwd = await gitBootstrap('fixtures/default'); + const actual = await cli(['--version'], {cwd})(); + expect(actual.stdout).toMatch('@commitlint/cli@'); +}); + +async function writePkg(payload: unknown, options: TestOptions) { const pkgPath = path.join(options.cwd, 'package.json'); const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8')); const result = merge(pkg, payload); diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.ts old mode 100755 new mode 100644 similarity index 58% rename from @commitlint/cli/src/cli.js rename to @commitlint/cli/src/cli.ts index 6ad0710816..6af2663f88 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.ts @@ -1,136 +1,139 @@ -#!/usr/bin/env node -import 'core-js/stable'; -import 'regenerator-runtime/runtime'; - import load from '@commitlint/load'; import lint from '@commitlint/lint'; import read from '@commitlint/read'; -import meow from 'meow'; -import {merge, pick, isFunction} from 'lodash'; +import isFunction from 'lodash/isFunction'; import stdin from 'get-stdin'; import resolveFrom from 'resolve-from'; import resolveGlobal from 'resolve-global'; +import yargs from 'yargs'; + +import {CliFlags, Seed} from './types'; +import { + LintOptions, + LintOutcome, + ParserOptions, + ParserPreset, + QualifiedConfig, + Formatter +} from '@commitlint/types'; +import {CliError} from './cli-error'; -import help from './help'; const pkg = require('../package'); -const flags = { - color: { - alias: 'c', - default: true, - description: 'toggle colored output', - type: 'boolean' - }, - config: { - alias: 'g', - default: null, - description: 'path to the config file', - type: 'string' - }, - cwd: { - alias: 'd', - default: process.cwd(), - description: 'directory to execute in', - type: 'string' - }, - edit: { - alias: 'e', - default: false, - description: - 'read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG', - type: 'string' - }, - env: { - alias: 'E', - default: null, - description: - 'check message in the file at path given by environment variable value', - type: 'string' - }, - extends: { - alias: 'x', - description: 'array of shareable configurations to extend', - type: 'string' - }, - help: { - alias: 'h', - type: 'boolean', - description: 'display this help message' - }, - 'help-url': { - alias: 'H', - type: 'string', - description: 'helpurl in error message' - }, - from: { - alias: 'f', - default: null, - description: 'lower end of the commit range to lint; applies if edit=false', - type: 'string' - }, - format: { - alias: 'o', - default: null, - description: 'output format of the results', - type: 'string' - }, - 'parser-preset': { - alias: 'p', - description: 'configuration preset to use for conventional-commits-parser', - type: 'string' - }, - quiet: { - alias: 'q', - default: false, - description: 'toggle console output', - type: 'boolean' - }, - to: { - alias: 't', - default: null, - description: 'upper end of the commit range to lint; applies if edit=false', - type: 'string' - }, - version: { - alias: 'v', - type: 'boolean', - description: 'display version information' - }, - verbose: { - alias: 'V', - type: 'boolean', - description: 'enable verbose output for reports without problems' - } -}; - -const cli = meow({ - description: `${pkg.name}@${pkg.version} - ${pkg.description}`, - flags, - help: `[input] reads from stdin if --edit, --env, --from and --to are omitted\n${help( - flags - )}`, - unknown(arg) { - throw new Error(`unknown flags: ${arg}`); - } -}); - -main(cli).catch(err => +const cli = yargs + .options({ + color: { + alias: 'c', + default: true, + description: 'toggle colored output', + type: 'boolean' + }, + config: { + alias: 'g', + description: 'path to the config file', + type: 'string' + }, + cwd: { + alias: 'd', + default: process.cwd(), + defaultDescription: '(Working Directory)', + description: 'directory to execute in', + type: 'string' + }, + edit: { + alias: 'e', + default: false, + description: + 'read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG', + type: 'string' + }, + env: { + alias: 'E', + description: + 'check message in the file at path given by environment variable value', + type: 'string' + }, + extends: { + alias: 'x', + description: 'array of shareable configurations to extend', + type: 'array' + }, + 'help-url': { + alias: 'H', + type: 'string', + description: 'help url in error message' + }, + from: { + alias: 'f', + description: + 'lower end of the commit range to lint; applies if edit=false', + type: 'string' + }, + format: { + alias: 'o', + description: 'output format of the results', + type: 'string' + }, + 'parser-preset': { + alias: 'p', + description: + 'configuration preset to use for conventional-commits-parser', + type: 'string' + }, + quiet: { + alias: 'q', + default: false, + description: 'toggle console output', + type: 'boolean' + }, + to: { + alias: 't', + description: + 'upper end of the commit range to lint; applies if edit=false', + type: 'string' + }, + verbose: { + alias: 'V', + type: 'boolean', + description: 'enable verbose output for reports without problems' + } + }) + .version( + 'version', + 'display version information', + `${pkg.name}@${pkg.version}` + ) + .alias('v', 'version') + .help('help') + .alias('h', 'help') + .usage(`${pkg.name}@${pkg.version} - ${pkg.description}\n`) + .usage( + `[input] reads from stdin if --edit, --env, --from and --to are omitted` + ) + .strict(); + +main(cli.argv).catch(err => { setTimeout(() => { if (err.type === pkg.name) { process.exit(1); } throw err; - }) -); + }, 0); +}); -async function main(options) { - const raw = options.input; - const flags = normalizeFlags(options.flags); +async function main(options: CliFlags) { + const raw = options._; + const flags = normalizeFlags(options); const fromStdin = checkFromStdin(raw, flags); - const range = pick(flags, 'edit', 'from', 'to'); - - const input = await (fromStdin ? stdin() : read(range, {cwd: flags.cwd})); + const input = await (fromStdin + ? stdin() + : read({ + to: flags.to, + from: flags.from, + edit: flags.edit, + cwd: flags.cwd + })); const messages = (Array.isArray(input) ? input : [input]) .filter(message => typeof message === 'string') @@ -138,11 +141,11 @@ async function main(options) { .filter(Boolean); if (messages.length === 0 && !checkFromRepository(flags)) { - const err = new Error( - '[input] is required: supply via stdin, or --env or --edit or --from and --to' + const err = new CliError( + '[input] is required: supply via stdin, or --env or --edit or --from and --to', + pkg.name ); - err.type = pkg.name; - console.log(`${cli.help}\n`); + yargs.showHelp('log'); console.log(err.message); throw err; } @@ -150,7 +153,7 @@ async function main(options) { const loadOpts = {cwd: flags.cwd, file: flags.config}; const loaded = await load(getSeed(flags), loadOpts); const parserOpts = selectParserOpts(loaded.parserPreset); - const opts = { + const opts: LintOptions & {parserOpts: ParserOptions} = { parserOpts: {}, plugins: {}, ignores: [], @@ -171,7 +174,7 @@ async function main(options) { const format = loadFormatter(loaded, flags); // Strip comments if reading from `.git/COMMIT_EDIT_MSG` - if (range.edit) { + if (flags.edit) { opts.parserOpts.commentChar = '#'; } @@ -183,8 +186,7 @@ async function main(options) { let input = ''; if (results.length !== 0) { - const originalInput = results[0].input; - input = originalInput; + input = results[0].input; } results.splice(0, results.length, { @@ -206,7 +208,12 @@ async function main(options) { }); } - const report = results.reduce( + const report = results.reduce<{ + valid: boolean; + errorCount: number; + warningCount: number; + results: LintOutcome[]; + }>( (info, result) => { info.valid = result.valid ? info.valid : false; info.errorCount += result.errors.length; @@ -226,8 +233,8 @@ async function main(options) { const output = format(report, { color: flags.color, verbose: flags.verbose, - helpUrl: flags.helpUrl - ? flags.helpUrl.trim() + helpUrl: flags['help-url'] + ? flags['help-url'].trim() : 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint' }); @@ -236,34 +243,35 @@ async function main(options) { } if (!report.valid) { - const err = new Error(output); - err.type = pkg.name; - throw err; + throw new CliError(output, pkg.name); } } -function checkFromStdin(input, flags) { +function checkFromStdin(input: string[], flags: CliFlags): boolean { return input.length === 0 && !checkFromRepository(flags); } -function checkFromRepository(flags) { +function checkFromRepository(flags: CliFlags) { return checkFromHistory(flags) || checkFromEdit(flags); } -function checkFromEdit(flags) { +function checkFromEdit(flags: CliFlags) { return Boolean(flags.edit) || flags.env; } -function checkFromHistory(flags) { +function checkFromHistory(flags: CliFlags): boolean { return typeof flags.from === 'string' || typeof flags.to === 'string'; } -function normalizeFlags(flags) { +function normalizeFlags(flags: CliFlags): CliFlags { const edit = getEditValue(flags); - return merge({}, flags, {edit, e: edit}); + return { + ...flags, + edit + }; } -function getEditValue(flags) { +function getEditValue(flags: CliFlags) { if (flags.env) { if (!(flags.env in process.env)) { throw new Error( @@ -311,15 +319,16 @@ function getEditValue(flags) { return edit; } -function getSeed(seed) { - const e = Array.isArray(seed.extends) ? seed.extends : [seed.extends]; - const n = e.filter(i => typeof i === 'string'); +function getSeed(flags: CliFlags): Seed { + const n = (flags.extends || []).filter( + (i): i is string => typeof i === 'string' + ); return n.length > 0 - ? {extends: n, parserPreset: seed.parserPreset} - : {parserPreset: seed.parserPreset}; + ? {extends: n, parserPreset: flags['parser-preset']} + : {parserPreset: flags['parser-preset']}; } -function selectParserOpts(parserPreset) { +function selectParserOpts(parserPreset: ParserPreset) { if (typeof parserPreset !== 'object') { return undefined; } @@ -331,7 +340,7 @@ function selectParserOpts(parserPreset) { return parserPreset.parserOpts; } -function loadFormatter(config, flags) { +function loadFormatter(config: QualifiedConfig, flags: CliFlags): Formatter { const moduleName = flags.format || config.formatter || '@commitlint/format'; const modulePath = resolveFrom.silent(__dirname, moduleName) || diff --git a/@commitlint/cli/src/help.js b/@commitlint/cli/src/help.js deleted file mode 100644 index 42c0d597c9..0000000000 --- a/@commitlint/cli/src/help.js +++ /dev/null @@ -1,34 +0,0 @@ -module.exports = flags => { - const lines = Object.entries(flags).map(entry => { - const name = entry[0]; - const value = entry[1]; - return [ - [name, value.alias].filter(Boolean), - value.description, - value.default - ].filter(Boolean); - }); - - const longest = lines - .map(line => { - const flags = line[0]; - return flags.reduce((sum, flag) => sum + flag.length, 0); - }) - .sort((a, b) => b - a)[0]; - - return lines - .map(line => { - const flags = line[0]; - const desc = line[1]; - const defaults = line[2]; - const fs = flags.map(flag => - flag.length > 1 ? `--${flag}` : ` -${flag}` - ); - const ds = defaults ? `, defaults to: ${defaults}` : ''; - const length = flags.reduce((sum, flag) => sum + flag.length, 0); - return `${fs.join(',')}${' '.repeat( - Math.max(4 + longest - length, 0) - )}${desc}${ds}`; - }) - .join('\n'); -}; diff --git a/@commitlint/cli/src/types.ts b/@commitlint/cli/src/types.ts new file mode 100644 index 0000000000..67dcc606a1 --- /dev/null +++ b/@commitlint/cli/src/types.ts @@ -0,0 +1,24 @@ +export interface CliFlags { + color: boolean; + config?: string; + cwd: string; + edit?: string | boolean; + env?: string; + extends?: (string | number)[]; + help?: boolean; + 'help-url'?: string; + from?: string; + format?: string; + 'parser-preset'?: string; + quiet: boolean; + to?: string; + version?: boolean; + verbose?: boolean; + _: string[]; + $0: string; +} + +export interface Seed { + extends?: string[]; + parserPreset?: string; +} diff --git a/@commitlint/cli/tsconfig.json b/@commitlint/cli/tsconfig.json new file mode 100644 index 0000000000..8d5ce01f6d --- /dev/null +++ b/@commitlint/cli/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.shared.json", + "compilerOptions": { + "composite": true, + "rootDir": "./src", + "outDir": "./lib" + }, + "include": ["./src/**/*.ts"], + "exclude": ["./src/**/*.test.ts", "./lib/**/*"] +} diff --git a/@commitlint/format/package.json b/@commitlint/format/package.json index bccd87518c..00f946f721 100644 --- a/@commitlint/format/package.json +++ b/@commitlint/format/package.json @@ -37,7 +37,16 @@ "@commitlint/utils": "^9.1.1" }, "dependencies": { +<<<<<<< HEAD "chalk": "^4.0.0" }, "gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca" +||||||| f74e036 + "chalk": "^3.0.0" + } +======= + "@commitlint/types": "^8.3.5", + "chalk": "^3.0.0" + } +>>>>>>> armano2/refactor-cli } diff --git a/@commitlint/format/src/format.ts b/@commitlint/format/src/format.ts index 050c8fba63..cf75cf824d 100644 --- a/@commitlint/format/src/format.ts +++ b/@commitlint/format/src/format.ts @@ -1,41 +1,19 @@ import chalk from 'chalk'; +import { + ChalkColor, + FormattableReport, + FormatOptions, + FormattableResult, + WithInput +} from '@commitlint/types'; const DEFAULT_SIGNS = [' ', '⚠', '✖'] as const; const DEFAULT_COLORS = ['white', 'yellow', 'red'] as const; -export interface FormattableProblem { - level: 0 | 1 | 2; - name: string; - message: string; -} - -export interface FormattableResult { - errors?: FormattableProblem[]; - warnings?: FormattableProblem[]; -} - -export interface WithInput { - input?: string; -} - -export interface FormattableReport { - results?: (FormattableResult & WithInput)[]; -} - -export type ChalkColor = keyof typeof chalk; - -export interface FormatOptions { - color?: boolean; - signs?: readonly [string, string, string]; - colors?: readonly [ChalkColor, ChalkColor, ChalkColor]; - verbose?: boolean; - helpUrl?: string; -} - export function format( report: FormattableReport = {}, options: FormatOptions = {} -) { +): string { const {results = []} = report; const fi = (result: FormattableResult & WithInput) => formatInput(result, options); diff --git a/@commitlint/format/tsconfig.json b/@commitlint/format/tsconfig.json index 49479bf34f..119e645565 100644 --- a/@commitlint/format/tsconfig.json +++ b/@commitlint/format/tsconfig.json @@ -6,5 +6,6 @@ "outDir": "./lib" }, "include": ["./src"], - "exclude": ["./src/**/*.test.ts", "./lib/**/*"] + "exclude": ["./src/**/*.test.ts", "./lib/**/*"], + "references": [{"path": "../types"}] } diff --git a/@commitlint/lint/src/lint.test.ts b/@commitlint/lint/src/lint.test.ts index 52ef073c13..9e4122cff2 100644 --- a/@commitlint/lint/src/lint.test.ts +++ b/@commitlint/lint/src/lint.test.ts @@ -128,8 +128,8 @@ test('throws for rule with invalid level', async () => { test('throws for rule with out of range level', async () => { const error = lint('type(scope): foo', { - 'type-enum': [-1, 'always'], - 'header-max-length': [3, 'always'] + 'type-enum': [-1, 'always'] as any, + 'header-max-length': [3, 'always'] as any }); await expect(error).rejects.toThrow('rule type-enum must be between 0 and 2'); diff --git a/@commitlint/lint/src/lint.ts b/@commitlint/lint/src/lint.ts index 6917d74611..1c10f43ec2 100644 --- a/@commitlint/lint/src/lint.ts +++ b/@commitlint/lint/src/lint.ts @@ -4,20 +4,27 @@ import parse from '@commitlint/parse'; import defaultRules from '@commitlint/rules'; import {buildCommitMesage} from './commit-message'; import { - LintRuleConfig, LintOptions, + LintOutcome, LintRuleOutcome, Rule, +<<<<<<< HEAD RuleSeverity, BaseRule, RuleType +||||||| f74e036 + RuleSeverity +======= + RuleConfigSeverity, + QualifiedRules +>>>>>>> armano2/refactor-cli } from '@commitlint/types'; export default async function lint( message: string, - rawRulesConfig?: LintRuleConfig, + rawRulesConfig?: QualifiedRules, rawOpts?: LintOptions -) { +): Promise { const opts = rawOpts ? rawOpts : {defaultIgnores: undefined, ignores: undefined}; @@ -95,7 +102,7 @@ export default async function lint( const [level] = config; - if (level === RuleSeverity.Disabled && config.length === 1) { + if (level === RuleConfigSeverity.Disabled && config.length === 1) { return null; } @@ -150,11 +157,21 @@ export default async function lint( } // Validate against all rules +<<<<<<< HEAD const pendingResults = Object.entries(rulesConfig) .filter(([, [level]]) => level > 0) .map(async entry => { +||||||| f74e036 + const results = Object.entries(rulesConfig) + .filter(([, [level]]) => level > 0) + .map(entry => { +======= + const results = Object.entries(rulesConfig) + .filter(([, config]) => typeof config !== 'undefined' && config[0] > 0) + .map(entry => { +>>>>>>> armano2/refactor-cli const [name, config] = entry; - const [level, when, value] = config; + const [level, when, value] = config!; // // Level 0 rules are ignored if (level === 0) { @@ -167,8 +184,15 @@ export default async function lint( throw new Error(`Could not find rule implementation for ${name}`); } +<<<<<<< HEAD const executableRule = rule as Rule; const [valid, message] = await executableRule(parsed, when, value); +||||||| f74e036 + const executableRule = rule as Rule; + const [valid, message] = executableRule(parsed, when, value); +======= + const [valid, message] = rule(parsed, when, value as any); +>>>>>>> armano2/refactor-cli return { level, diff --git a/@commitlint/types/src/format.ts b/@commitlint/types/src/format.ts new file mode 100644 index 0000000000..ba50d8a79f --- /dev/null +++ b/@commitlint/types/src/format.ts @@ -0,0 +1,37 @@ +import chalk from 'chalk'; +import {QualifiedRules} from './load'; +import {RuleConfigSeverity} from './rules'; + +export type Formatter = ( + report: FormattableReport, + options: FormatOptions +) => string; + +export interface FormattableProblem { + level: RuleConfigSeverity; + name: keyof QualifiedRules; + message: string; +} + +export interface FormattableResult { + errors?: FormattableProblem[]; + warnings?: FormattableProblem[]; +} + +export interface WithInput { + input?: string; +} + +export interface FormattableReport { + results?: (FormattableResult & WithInput)[]; +} + +export type ChalkColor = keyof typeof chalk; + +export interface FormatOptions { + color?: boolean; + signs?: readonly [string, string, string]; + colors?: readonly [ChalkColor, ChalkColor, ChalkColor]; + verbose?: boolean; + helpUrl?: string; +} diff --git a/@commitlint/types/src/index.ts b/@commitlint/types/src/index.ts index f562854fed..562a9a6373 100644 --- a/@commitlint/types/src/index.ts +++ b/@commitlint/types/src/index.ts @@ -1,4 +1,5 @@ export * from './ensure'; +export * from './format'; export * from './is-ignored'; export * from './rules'; export * from './lint'; diff --git a/@commitlint/types/src/lint.ts b/@commitlint/types/src/lint.ts index 6ebf81e448..e9f047e9e0 100644 --- a/@commitlint/types/src/lint.ts +++ b/@commitlint/types/src/lint.ts @@ -1,10 +1,11 @@ import {IsIgnoredOptions} from './is-ignored'; -import {RuleConfigTuple, PluginRecords, RuleSeverity} from './load'; +import {PluginRecords} from './load'; import {ParserOptions} from './parse'; +import {RuleConfigSeverity, RuleConfigTuple} from './rules'; export type LintRuleConfig = Record< string, - | Readonly<[RuleSeverity.Disabled]> + | Readonly<[RuleConfigSeverity.Disabled]> | RuleConfigTuple | RuleConfigTuple >; @@ -35,7 +36,7 @@ export interface LintRuleOutcome { /** If the commit is considered valid for the rule */ valid: boolean; /** The "severity" of the rule (1 = warning, 2 = error) */ - level: RuleSeverity; + level: RuleConfigSeverity; /** The name of the rule */ name: string; /** The message returned from the rule, if invalid */ diff --git a/@commitlint/types/src/load.ts b/@commitlint/types/src/load.ts index d6feebca38..cfcd59acc4 100644 --- a/@commitlint/types/src/load.ts +++ b/@commitlint/types/src/load.ts @@ -1,5 +1,4 @@ -import {TargetCaseType} from './ensure'; -import {Rule, RuleCondition} from './rules'; +import {Rule, RulesConfig, RuleConfigQuality} from './rules'; export type PluginRecords = Record; @@ -14,84 +13,9 @@ export interface LoadOptions { file?: string; } -export enum RuleSeverity { - Disabled = 0, - Warning = 1, - Error = 2 -} - -export type RuleConfigTuple = T extends void - ? Readonly<[RuleSeverity, RuleCondition]> - : Readonly<[RuleSeverity, RuleCondition, T]>; - -export enum RuleConfigQuality { - User, - Qualified -} - -export type QualifiedRuleConfig = - | (() => RuleConfigTuple) - | (() => RuleConfigTuple>) - | RuleConfigTuple; - -export type RuleConfig< - V = RuleConfigQuality.Qualified, - T = void -> = V extends RuleConfigQuality.Qualified - ? RuleConfigTuple - : QualifiedRuleConfig; - -export type CaseRuleConfig = RuleConfig< - V, - TargetCaseType ->; -export type LengthRuleConfig = RuleConfig< - V, - number ->; -export type EnumRuleConfig = RuleConfig< - V, - string[] ->; - -export type RulesConfig = { - 'body-case': CaseRuleConfig; - 'body-empty': RuleConfig; - 'body-leading-blank': RuleConfig; - 'body-max-length': LengthRuleConfig; - 'body-max-line-length': LengthRuleConfig; - 'body-min-length': LengthRuleConfig; - 'footer-empty': RuleConfig; - 'footer-leading-blank': RuleConfig; - 'footer-max-length': LengthRuleConfig; - 'footer-max-line-length': LengthRuleConfig; - 'footer-min-length': LengthRuleConfig; - 'header-case': CaseRuleConfig; - 'header-full-stop': RuleConfig; - 'header-max-length': LengthRuleConfig; - 'header-min-length': LengthRuleConfig; - 'references-empty': RuleConfig; - 'scope-case': CaseRuleConfig; - 'scope-empty': RuleConfig; - 'scope-enum': EnumRuleConfig; - 'scope-max-length': LengthRuleConfig; - 'scope-min-length': LengthRuleConfig; - 'signed-off-by': RuleConfig; - 'subject-case': CaseRuleConfig; - 'subject-empty': RuleConfig; - 'subject-full-stop': RuleConfig; - 'subject-max-length': LengthRuleConfig; - 'subject-min-length': LengthRuleConfig; - 'type-case': CaseRuleConfig; - 'type-empty': RuleConfig; - 'type-enum': EnumRuleConfig; - 'type-max-length': LengthRuleConfig; - 'type-min-length': LengthRuleConfig; -}; - export interface UserConfig { extends?: string[]; - formatter?: unknown; + formatter?: string; rules?: Partial; parserPreset?: string | ParserPreset; ignores?: ((commit: string) => boolean)[]; @@ -101,7 +25,7 @@ export interface UserConfig { export interface UserPreset { extends?: string[]; - formatter?: unknown; + formatter?: string; rules?: Partial; parserPreset?: string | ParserPreset; ignores?: ((commit: string) => boolean)[]; @@ -113,8 +37,8 @@ export type QualifiedRules = Partial>; export interface QualifiedConfig { extends: string[]; - formatter: unknown; - rules: Partial; + formatter: string; + rules: QualifiedRules; parserPreset: ParserPreset; ignores: ((commit: string) => boolean)[]; defaultIgnores: boolean; diff --git a/@commitlint/types/src/rules.ts b/@commitlint/types/src/rules.ts index 3d99db4059..be57da0c88 100644 --- a/@commitlint/types/src/rules.ts +++ b/@commitlint/types/src/rules.ts @@ -1,12 +1,6 @@ +import {TargetCaseType} from './ensure'; import {Commit} from './parse'; -/** - * Rules always have a condition. - * It can be either "always" (as tested), or "never" (as tested). - * For example, `header-full-stop` can be enforced as "always" or "never". - */ -export type RuleCondition = 'always' | 'never'; - /** * Rules match the input either as successful or failed. * For example, when `header-full-stop` detects a full stop and is set as "always"; it's true. @@ -22,8 +16,9 @@ export type RuleType = 'async' | 'sync' | 'either'; export type BaseRule = ( parsed: Commit, - when?: RuleCondition, + when?: RuleConfigCondition, value?: Value +<<<<<<< HEAD ) => Type extends 'either' ? RuleOutcome | Promise : Type extends 'async' @@ -35,3 +30,105 @@ export type BaseRule = ( export type Rule = BaseRule; export type AsyncRule = BaseRule; export type SyncRule = BaseRule; +||||||| f74e036 +) => RuleOutcome; +======= +) => RuleOutcome; + +/** + * Rules always have a severity. + * Severity indicates what to do if the rule is found to be broken + * 0 - Disable this rule + * 1 - Warn for violations + * 2 - Error for violations + */ +export enum RuleConfigSeverity { + Disabled = 0, + Warning = 1, + Error = 2 +} + +/** + * Rules always have a condition. + * It can be either "always" (as tested), or "never" (as tested). + * For example, `header-full-stop` can be enforced as "always" or "never". + */ +export type RuleConfigCondition = 'always' | 'never'; + +export type RuleConfigTuple = T extends void + ? + | Readonly<[RuleConfigSeverity.Disabled]> + | Readonly<[RuleConfigSeverity, RuleConfigCondition]> + : + | Readonly<[RuleConfigSeverity.Disabled]> + | Readonly<[RuleConfigSeverity, RuleConfigCondition, T]>; + +export enum RuleConfigQuality { + User, + Qualified +} + +export type QualifiedRuleConfig = + | (() => RuleConfigTuple) + | (() => RuleConfigTuple>) + | RuleConfigTuple; + +export type RuleConfig< + V = RuleConfigQuality.Qualified, + T = void +> = V extends RuleConfigQuality.Qualified + ? RuleConfigTuple + : QualifiedRuleConfig; + +export type CaseRuleConfig = RuleConfig< + V, + TargetCaseType +>; +export type LengthRuleConfig = RuleConfig< + V, + number +>; +export type EnumRuleConfig = RuleConfig< + V, + string[] +>; + +export type RulesConfig = { + 'body-case': CaseRuleConfig; + 'body-empty': RuleConfig; + 'body-leading-blank': RuleConfig; + 'body-max-length': LengthRuleConfig; + 'body-max-line-length': LengthRuleConfig; + 'body-min-length': LengthRuleConfig; + 'footer-empty': RuleConfig; + 'footer-leading-blank': RuleConfig; + 'footer-max-length': LengthRuleConfig; + 'footer-max-line-length': LengthRuleConfig; + 'footer-min-length': LengthRuleConfig; + 'header-case': CaseRuleConfig; + 'header-full-stop': RuleConfig; + 'header-max-length': LengthRuleConfig; + 'header-min-length': LengthRuleConfig; + 'references-empty': RuleConfig; + 'scope-case': CaseRuleConfig; + 'scope-empty': RuleConfig; + 'scope-enum': EnumRuleConfig; + 'scope-max-length': LengthRuleConfig; + 'scope-min-length': LengthRuleConfig; + 'signed-off-by': RuleConfig; + 'subject-case': CaseRuleConfig; + 'subject-empty': RuleConfig; + 'subject-full-stop': RuleConfig; + 'subject-max-length': LengthRuleConfig; + 'subject-min-length': LengthRuleConfig; + 'type-case': CaseRuleConfig; + 'type-empty': RuleConfig; + 'type-enum': EnumRuleConfig; + 'type-max-length': LengthRuleConfig; + 'type-min-length': LengthRuleConfig; + // Plugins may add their custom rules + [key: string]: AnyRuleConfig; +}; + +export type AnyRuleConfig = RuleConfig | RuleConfig; +>>>>>>> armano2/refactor-cli diff --git a/docs/reference-cli.md b/docs/reference-cli.md index 44261fc6e2..3f0b66a6c1 100644 --- a/docs/reference-cli.md +++ b/docs/reference-cli.md @@ -3,21 +3,31 @@ ```bash ❯ npx commitlint --help -@commitlint/cli@8.0.0 - Lint your commit messages +@commitlint/cli@8.3.5 - Lint your commit messages [input] reads from stdin if --edit, --env, --from and --to are omitted ---color, -c toggle colored output, defaults to: true ---config, -g path to the config file ---cwd, -d directory to execute in, defaults to: $CD ---edit, -e read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG ---env, -E check message in the file at path given by environment variable value ---extends, -x array of shareable configurations to extend ---help, -h display this help message ---from, -f lower end of the commit range to lint; applies if edit=false ---format, -o output format of the results ---parser-preset, -p configuration preset to use for conventional-commits-parser ---quiet, -q toggle console output ---to, -t upper end of the commit range to lint; applies if edit=false ---version, -v display version information ---verbose, -V enable verbose output for reports without problems + +Options: + --color, -c toggle colored output [boolean] [default: true] + --config, -g path to the config file [string] + --cwd, -d directory to execute in [string] [default: cwd] + --edit, -e read last commit message from the specified file or + fallbacks to ./.git/COMMIT_EDITMSG + [string] [default: false] + --env, -E check message in the file at path given by environment + variable value [string] + --extends, -x array of shareable configurations to extend [array] + --help-url, -H helpurl in error message [string] + --from, -f lower end of the commit range to lint; applies if + edit=false [string] + --format, -o output format of the results [string] + --parser-preset, -p configuration preset to use for + conventional-commits-parser [string] + --quiet, -q toggle console output [boolean] [default: false] + --to, -t upper end of the commit range to lint; applies if + edit=false [string] + --verbose, -V enable verbose output for reports without problems + [boolean] + -v, --version display version information [boolean] + -h, --help Show help [boolean] ``` diff --git a/tsconfig.json b/tsconfig.json index ca6bc60377..fd1d9d995a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,7 @@ {"path": "@commitlint/read"}, {"path": "@commitlint/rules"}, {"path": "@commitlint/lint"}, - {"path": "@commitlint/core"} + {"path": "@commitlint/core"}, + {"path": "@commitlint/cli"} ] } diff --git a/yarn.lock b/yarn.lock index ce7eb9d15e..e15b0bf90b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2620,7 +2620,7 @@ resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-13.1.0.tgz#c563aa192f39350a1d18da36c5a8da382bbd8228" integrity sha512-gCubfBUZ6KxzoibJ+SCUc/57Ms1jz5NjHe4+dI2krNmU5zCPAphyLJYyTOg06ueIyfj+SaCUqmzun7ImlxDcKg== -"@types/yargs@^15.0.0": +"@types/yargs@^15.0.0", "@types/yargs@^15.0.3": version "15.0.3" resolved "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz#41453a0bc7ab393e995d1f5451455638edbd2baf" integrity sha512-XCMQRK6kfpNBixHLyHUsGmXrpEmFFxzMrcnSXFMziHd8CoNJo8l16FkHyQq4x+xbM7E2XL83/O78OD8u+iZTdQ== @@ -4180,11 +4180,6 @@ core-js@^2.4.0, core-js@^2.5.0: resolved "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz#38831469f9922bded8ee21c9dc46985e0399308c" integrity sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg== -core-js@^3.6.1: - version "3.6.1" - resolved "https://registry.npmjs.org/core-js/-/core-js-3.6.1.tgz#39d5e2e346258cc01eb7d44345b1c3c014ca3f05" - integrity sha512-186WjSik2iTGfDjfdCZAxv2ormxtKgemjC3SI6PL31qOA0j5LhTDVjHChccoc7brwLvpvLPiMyRlcO88C4l1QQ== - core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -7693,21 +7688,6 @@ meow@4.0.1, meow@^4.0.0: redent "^2.0.0" trim-newlines "^2.0.0" -meow@5.0.0, meow@^5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/meow/-/meow-5.0.0.tgz#dfc73d63a9afc714a5e371760eb5c88b91078aa4" - integrity sha512-CbTqYU17ABaLefO8vCU153ZZlprKYWDljcndKKDCFcYQITzWCXZAVk4QMFZPgvzrnUQ3uItnIE/LoUOwrT15Ig== - dependencies: - camelcase-keys "^4.0.0" - decamelize-keys "^1.0.0" - loud-rejection "^1.0.0" - minimist-options "^3.0.1" - normalize-package-data "^2.3.4" - read-pkg-up "^3.0.0" - redent "^2.0.0" - trim-newlines "^2.0.0" - yargs-parser "^10.0.0" - meow@^3.3.0: version "3.7.0" resolved "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb" @@ -7724,6 +7704,21 @@ meow@^3.3.0: redent "^1.0.0" trim-newlines "^1.0.0" +meow@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/meow/-/meow-5.0.0.tgz#dfc73d63a9afc714a5e371760eb5c88b91078aa4" + integrity sha512-CbTqYU17ABaLefO8vCU153ZZlprKYWDljcndKKDCFcYQITzWCXZAVk4QMFZPgvzrnUQ3uItnIE/LoUOwrT15Ig== + dependencies: + camelcase-keys "^4.0.0" + decamelize-keys "^1.0.0" + loud-rejection "^1.0.0" + minimist-options "^3.0.1" + normalize-package-data "^2.3.4" + read-pkg-up "^3.0.0" + redent "^2.0.0" + trim-newlines "^2.0.0" + yargs-parser "^10.0.0" + merge-stream@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" @@ -9213,11 +9208,20 @@ regenerate@^1.4.0: resolved "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== +<<<<<<< HEAD regenerator-runtime@0.13.5, regenerator-runtime@^0.13.4: version "0.13.5" resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697" integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA== +||||||| f74e036 +regenerator-runtime@0.13.3, regenerator-runtime@^0.13.2: + version "0.13.3" + resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5" + integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw== + +======= +>>>>>>> armano2/refactor-cli regenerator-runtime@^0.10.5: version "0.10.5" resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" @@ -9456,6 +9460,7 @@ resolve@1.1.7: resolved "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= +<<<<<<< HEAD resolve@^1.10.0, resolve@^1.13.1, resolve@^1.17.0: version "1.17.0" resolved "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444" @@ -9464,6 +9469,11 @@ resolve@^1.10.0, resolve@^1.13.1, resolve@^1.17.0: path-parse "^1.0.6" resolve@^1.3.2, resolve@^1.8.1: +||||||| f74e036 +resolve@1.x, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.3.2, resolve@^1.8.1, resolve@^1.12.0, resolve@^1.13.1: +======= +resolve@1.x, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.3.2, resolve@^1.8.1: +>>>>>>> armano2/refactor-cli version "1.15.1" resolved "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz#27bdcdeffeaf2d6244b95bb0f9f4b4653451f3e8" integrity sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w== @@ -11231,7 +11241,7 @@ yargs@^14.2.2: y18n "^4.0.0" yargs-parser "^15.0.0" -yargs@^15.0.0: +yargs@^15.0.0, yargs@^15.1.0: version "15.1.0" resolved "https://registry.npmjs.org/yargs/-/yargs-15.1.0.tgz#e111381f5830e863a89550bd4b136bb6a5f37219" integrity sha512-T39FNN1b6hCW4SOIk1XyTOWxtXdcen0t+XYrysQmChzSipvhBO8Bj0nK1ozAasdk24dNWuMZvr4k24nz+8HHLg== From d8cdc7fb9548bee1a22f956c23ca35d71b13bd5c Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Sun, 12 Jul 2020 11:23:38 +0200 Subject: [PATCH 2/2] refactor: merge cli typescript refactor with conflicts Fixes #1691 --- @commitlint/cli/package.json | 48 +---------------- @commitlint/cli/src/cli.test.ts | 2 +- @commitlint/config-patternplate/package.json | 2 +- @commitlint/ensure/package.json | 2 +- @commitlint/format/package.json | 11 +--- @commitlint/lint/src/lint.ts | 35 ++----------- @commitlint/load/package.json | 2 +- @commitlint/prompt/package.json | 2 +- @commitlint/resolve-extends/package.json | 2 +- @commitlint/types/src/rules.ts | 6 --- package.json | 2 +- yarn.lock | 54 ++++++++------------ 12 files changed, 36 insertions(+), 132 deletions(-) diff --git a/@commitlint/cli/package.json b/@commitlint/cli/package.json index a35d1fb28c..4c755126e2 100644 --- a/@commitlint/cli/package.json +++ b/@commitlint/cli/package.json @@ -36,30 +36,17 @@ }, "license": "MIT", "devDependencies": { -<<<<<<< HEAD "@babel/cli": "^7.7.7", "@babel/core": "^7.7.7", "@commitlint/test": "^9.1.1", "@commitlint/utils": "^9.1.1", + "@types/yargs": "^15.0.3", "babel-preset-commitlint": "^9.1.1", "cross-env": "7.0.2", -||||||| f74e036 - "@babel/cli": "^7.7.7", - "@babel/core": "^7.7.7", - "@commitlint/test": "8.2.0", - "@commitlint/utils": "^8.3.4", - "babel-preset-commitlint": "^8.2.0", - "cross-env": "7.0.0", -======= - "@types/yargs": "^15.0.3", - "@commitlint/test": "8.2.0", - "@commitlint/utils": "^8.3.4", ->>>>>>> armano2/refactor-cli "execa": "^3.4.0", "fs-extra": "^8.1.0" }, "dependencies": { -<<<<<<< HEAD "@babel/runtime": "^7.9.6", "@commitlint/format": "^9.1.1", "@commitlint/lint": "^9.1.1", @@ -67,41 +54,10 @@ "@commitlint/read": "^9.1.1", "chalk": "4.1.0", "core-js": "^3.6.1", -||||||| f74e036 - "@commitlint/format": "^8.3.4", - "@commitlint/lint": "^8.3.5", - "@commitlint/load": "^8.3.5", - "@commitlint/read": "^8.3.4", - "chalk": "3.0.0", - "core-js": "^3.6.1", -======= - "@commitlint/format": "^8.3.4", - "@commitlint/lint": "^8.3.5", - "@commitlint/load": "^8.3.5", - "@commitlint/read": "^8.3.4", - "chalk": "3.0.0", ->>>>>>> armano2/refactor-cli "get-stdin": "7.0.0", - "lodash": "^4.17.15", -<<<<<<< HEAD - "meow": "5.0.0", - "regenerator-runtime": "0.13.5", -||||||| f74e036 - "meow": "5.0.0", - "regenerator-runtime": "0.13.3", -======= ->>>>>>> armano2/refactor-cli + "lodash": "^4.17.19", "resolve-from": "5.0.0", -<<<<<<< HEAD - "resolve-global": "1.0.0" - }, - "gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca" -||||||| f74e036 - "resolve-global": "1.0.0" - } -======= "resolve-global": "1.0.0", "yargs": "^15.1.0" } ->>>>>>> armano2/refactor-cli } diff --git a/@commitlint/cli/src/cli.test.ts b/@commitlint/cli/src/cli.test.ts index 0ab9c60560..b19177c6e8 100644 --- a/@commitlint/cli/src/cli.test.ts +++ b/@commitlint/cli/src/cli.test.ts @@ -432,7 +432,7 @@ test('should print help', async () => { const cwd = await gitBootstrap('fixtures/default'); const actual = await cli(['--help'], {cwd})(); expect(actual.stdout).toMatchInlineSnapshot(` - "@commitlint/cli@8.3.5 - Lint your commit messages + "@commitlint/cli@9.1.1 - Lint your commit messages [input] reads from stdin if --edit, --env, --from and --to are omitted diff --git a/@commitlint/config-patternplate/package.json b/@commitlint/config-patternplate/package.json index dd9fd6900d..46e0ccd973 100644 --- a/@commitlint/config-patternplate/package.json +++ b/@commitlint/config-patternplate/package.json @@ -31,7 +31,7 @@ "dependencies": { "@commitlint/config-angular": "^9.1.1", "globby": "^11.0.0", - "lodash": "^4.17.15" + "lodash": "^4.17.19" }, "devDependencies": { "@commitlint/utils": "^9.1.1" diff --git a/@commitlint/ensure/package.json b/@commitlint/ensure/package.json index 5d2f2f0d9b..2cacf4aa18 100644 --- a/@commitlint/ensure/package.json +++ b/@commitlint/ensure/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@commitlint/types": "^9.1.1", - "lodash": "^4.17.15" + "lodash": "^4.17.19" }, "gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca" } diff --git a/@commitlint/format/package.json b/@commitlint/format/package.json index 00f946f721..8f4569b6cc 100644 --- a/@commitlint/format/package.json +++ b/@commitlint/format/package.json @@ -37,16 +37,7 @@ "@commitlint/utils": "^9.1.1" }, "dependencies": { -<<<<<<< HEAD + "@commitlint/types": "^9.1.1", "chalk": "^4.0.0" - }, - "gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca" -||||||| f74e036 - "chalk": "^3.0.0" - } -======= - "@commitlint/types": "^8.3.5", - "chalk": "^3.0.0" } ->>>>>>> armano2/refactor-cli } diff --git a/@commitlint/lint/src/lint.ts b/@commitlint/lint/src/lint.ts index 1c10f43ec2..3fd0204876 100644 --- a/@commitlint/lint/src/lint.ts +++ b/@commitlint/lint/src/lint.ts @@ -8,16 +8,10 @@ import { LintOutcome, LintRuleOutcome, Rule, -<<<<<<< HEAD - RuleSeverity, - BaseRule, - RuleType -||||||| f74e036 - RuleSeverity -======= RuleConfigSeverity, + BaseRule, + RuleType, QualifiedRules ->>>>>>> armano2/refactor-cli } from '@commitlint/types'; export default async function lint( @@ -157,42 +151,21 @@ export default async function lint( } // Validate against all rules -<<<<<<< HEAD const pendingResults = Object.entries(rulesConfig) - .filter(([, [level]]) => level > 0) + // Level 0 rules are ignored + .filter(([, config]) => !!config && config.length && config[0] > 0) .map(async entry => { -||||||| f74e036 - const results = Object.entries(rulesConfig) - .filter(([, [level]]) => level > 0) - .map(entry => { -======= - const results = Object.entries(rulesConfig) - .filter(([, config]) => typeof config !== 'undefined' && config[0] > 0) - .map(entry => { ->>>>>>> armano2/refactor-cli const [name, config] = entry; const [level, when, value] = config!; // - // Level 0 rules are ignored - if (level === 0) { - return null; - } - const rule = allRules.get(name); if (!rule) { throw new Error(`Could not find rule implementation for ${name}`); } -<<<<<<< HEAD const executableRule = rule as Rule; const [valid, message] = await executableRule(parsed, when, value); -||||||| f74e036 - const executableRule = rule as Rule; - const [valid, message] = executableRule(parsed, when, value); -======= - const [valid, message] = rule(parsed, when, value as any); ->>>>>>> armano2/refactor-cli return { level, diff --git a/@commitlint/load/package.json b/@commitlint/load/package.json index 55ae96c5b3..a516c1e146 100644 --- a/@commitlint/load/package.json +++ b/@commitlint/load/package.json @@ -45,7 +45,7 @@ "@commitlint/types": "^9.1.1", "chalk": "4.1.0", "cosmiconfig": "^6.0.0", - "lodash": "^4.17.15", + "lodash": "^4.17.19", "resolve-from": "^5.0.0" }, "gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca" diff --git a/@commitlint/prompt/package.json b/@commitlint/prompt/package.json index 4dc15fcbe4..25f20fc708 100644 --- a/@commitlint/prompt/package.json +++ b/@commitlint/prompt/package.json @@ -59,7 +59,7 @@ "@babel/runtime": "^7.9.6", "@commitlint/load": "^9.1.1", "chalk": "^4.0.0", - "lodash": "^4.17.15", + "lodash": "^4.17.19", "throat": "^5.0.0", "vorpal": "^1.12.0" }, diff --git a/@commitlint/resolve-extends/package.json b/@commitlint/resolve-extends/package.json index 0237c0dfc2..5a6acf63ce 100644 --- a/@commitlint/resolve-extends/package.json +++ b/@commitlint/resolve-extends/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "import-fresh": "^3.0.0", - "lodash": "^4.17.15", + "lodash": "^4.17.19", "resolve-from": "^5.0.0", "resolve-global": "^1.0.0" }, diff --git a/@commitlint/types/src/rules.ts b/@commitlint/types/src/rules.ts index be57da0c88..2a4d063a88 100644 --- a/@commitlint/types/src/rules.ts +++ b/@commitlint/types/src/rules.ts @@ -18,7 +18,6 @@ export type BaseRule = ( parsed: Commit, when?: RuleConfigCondition, value?: Value -<<<<<<< HEAD ) => Type extends 'either' ? RuleOutcome | Promise : Type extends 'async' @@ -30,10 +29,6 @@ export type BaseRule = ( export type Rule = BaseRule; export type AsyncRule = BaseRule; export type SyncRule = BaseRule; -||||||| f74e036 -) => RuleOutcome; -======= -) => RuleOutcome; /** * Rules always have a severity. @@ -131,4 +126,3 @@ export type RulesConfig = { }; export type AnyRuleConfig = RuleConfig | RuleConfig; ->>>>>>> armano2/refactor-cli diff --git a/package.json b/package.json index a811f2cae1..85d3f0f5d3 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,6 @@ } }, "resolutions": { - "**/lodash": "4.17.15" + "**/lodash": "4.17.19" } } diff --git a/yarn.lock b/yarn.lock index e15b0bf90b..e04d44c23d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4180,6 +4180,11 @@ core-js@^2.4.0, core-js@^2.5.0: resolved "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz#38831469f9922bded8ee21c9dc46985e0399308c" integrity sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg== +core-js@^3.6.1: + version "3.6.5" + resolved "https://registry.npmjs.org/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a" + integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA== + core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -7496,10 +7501,10 @@ lodash.uniq@^4.5.0: resolved "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@4.17.15, lodash@^3.3.1, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1: - version "4.17.15" - resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" - integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== +lodash@4.17.15, lodash@4.17.19, lodash@^3.3.1, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1: + version "4.17.19" + resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" + integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== log-symbols@^4.0.0: version "4.0.0" @@ -9208,20 +9213,6 @@ regenerate@^1.4.0: resolved "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== -<<<<<<< HEAD -regenerator-runtime@0.13.5, regenerator-runtime@^0.13.4: - version "0.13.5" - resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697" - integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA== - -||||||| f74e036 -regenerator-runtime@0.13.3, regenerator-runtime@^0.13.2: - version "0.13.3" - resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5" - integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw== - -======= ->>>>>>> armano2/refactor-cli regenerator-runtime@^0.10.5: version "0.10.5" resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" @@ -9237,6 +9228,11 @@ regenerator-runtime@^0.13.2: resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5" integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw== +regenerator-runtime@^0.13.4: + version "0.13.5" + resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697" + integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA== + regenerator-transform@^0.14.0: version "0.14.1" resolved "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.14.1.tgz#3b2fce4e1ab7732c08f665dfdb314749c7ddd2fb" @@ -9460,26 +9456,20 @@ resolve@1.1.7: resolved "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= -<<<<<<< HEAD -resolve@^1.10.0, resolve@^1.13.1, resolve@^1.17.0: - version "1.17.0" - resolved "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444" - integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w== - dependencies: - path-parse "^1.0.6" - -resolve@^1.3.2, resolve@^1.8.1: -||||||| f74e036 -resolve@1.x, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.3.2, resolve@^1.8.1, resolve@^1.12.0, resolve@^1.13.1: -======= -resolve@1.x, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.3.2, resolve@^1.8.1: ->>>>>>> armano2/refactor-cli +resolve@^1.10.0, resolve@^1.13.1, resolve@^1.3.2, resolve@^1.8.1: version "1.15.1" resolved "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz#27bdcdeffeaf2d6244b95bb0f9f4b4653451f3e8" integrity sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w== dependencies: path-parse "^1.0.6" +resolve@^1.17.0: + version "1.17.0" + resolved "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444" + integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w== + dependencies: + path-parse "^1.0.6" + responselike@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz#918720ef3b631c5642be068f15ade5a46f4ba1e7"