diff --git a/README.md b/README.md index ec3ce09..4a175c5 100644 --- a/README.md +++ b/README.md @@ -109,13 +109,16 @@ Run _foliant-md-linter_ from the project root with following commands and option - `-v`, `-s`, `-c`, `-p`, `-d`, `-f`, `-l` - `fix` Fix formatting errors with markdownlint - `-v`, `-s`, `-c`, `-p`, `-d`, `-f`, `-l` +- `typograph` Fix typograph errors with markdownlint + - `-v`, `-s`, `-c`, `-p`, `-d`, `-f`, `-l` - `print` Print linting results - `-v` - `create-full-config` Create markdownlint config for styleguide adherence - `-s`, `-p`, `-d` - `create-slim-config` Create markdownlint config for critical errors check - `-s`, `-p`, `-d` - +- `create-typograph-config` Create typograph config for typograph errors check + - `-s`, `-p`, `-d` ### Examples diff --git a/generate.js b/generate.js index fc949f6..0c5827a 100755 --- a/generate.js +++ b/generate.js @@ -65,6 +65,8 @@ function createConfig (mode = 'full', source = '', project = '') { MD049: { style: 'underscore' }, MD050: { style: 'asterisk' }, MD051: false, + MD052: true, + MD053: false, 'indented-fence': true, 'non-literal-fence-label': true, 'fenced-code-in-quote': true, @@ -111,6 +113,8 @@ function createConfig (mode = 'full', source = '', project = '') { MD049: false, MD050: false, MD051: false, + MD052: true, + MD053: false, 'indented-fence': true, 'non-literal-fence-label': true, 'fenced-code-in-quote': true, @@ -121,11 +125,67 @@ function createConfig (mode = 'full', source = '', project = '') { } } + const configTypograph = { + MD001: false, + MD003: false, + MD004: false, + MD005: false, + MD007: false, + MD009: false, + MD010: false, + MD011: false, + MD012: false, + MD013: false, + MD014: false, + MD018: false, + MD019: false, + MD020: false, + MD021: false, + MD022: false, + MD023: false, + MD024: false, + MD025: false, + MD026: false, + MD027: false, + MD028: false, + MD029: false, + MD030: false, + MD031: false, + MD032: false, + MD033: false, + MD034: false, + MD035: false, + MD036: false, + MD037: false, + MD038: false, + MD040: false, + MD041: false, + MD042: false, + MD043: false, + MD044: false, + MD045: false, + MD046: false, + MD047: false, + MD048: false, + MD049: false, + MD050: false, + MD051: false, + MD052: false, + MD053: false, + 'indented-fence': false, + 'non-literal-fence-label': false, + 'fenced-code-in-quote': false, + typograph: true, + 'validate-internal-links': false + } + let config if (mode === 'slim') { config = configSlim } else if (mode === 'default') { return null + } else if (mode === 'typograph') { + config = configTypograph } else { config = configFull } @@ -135,13 +195,14 @@ function createConfig (mode = 'full', source = '', project = '') { } const json = JSON.stringify(obj, null, 4) fs.writeFileSync(path.resolve(cwd, '.markdownlint-cli2.jsonc'), json, 'utf8') + console.log(`${mode} markdownlint config created succesfully!`) } program .name('create-markdownlint-config') .description('script for generating .markdownlint-cli2.jsonc in foliant-project root') .version('0.0.1') - .option('-m, --mode ', 'full, slim or default config', 'full') + .option('-m, --mode ', 'full, slim, typograph or default config', 'full') .option('-s, --source ', 'relative path to source directory', '') .option('-p, --project ', 'project name', '') diff --git a/linter.js b/linter.js index ec836e2..e39fc22 100755 --- a/linter.js +++ b/linter.js @@ -137,9 +137,11 @@ const commandsGen = function (src = defaultSrc, customConfig = false, project = const and = (isWin === true) ? '&' : ';' commands.createFullMarkdownlintConfig = (customConfig === false) ? `node ${path.join(__dirname, '/generate.js')} -m full -s ${src} -p "${project}"` : 'echo "using custom config"' commands.createSlimMarkdownlintConfig = (customConfig === false) ? `node ${path.join(__dirname, '/generate.js')} -m slim -s ${src} -p "${project}"` : 'echo "using custom config"' + commands.createTypographMarkdownlintConfig = (customConfig === false) ? `node ${path.join(__dirname, '/generate.js')} -m typograph -s ${src} -p "${project}"` : 'echo "using custom config"' commands.markdownlintSrcSlim = `${commands.createSlimMarkdownlintConfig} && ${execPath}/markdownlint-cli2 "${src}/**/*.md" ${writeLog(markdownLintSlimLog)}` commands.markdownlintSrcFull = `${commands.markdownlintSrcSlim} ${and} ${commands.createFullMarkdownlintConfig} && ${execPath}/markdownlint-cli2 "${src}/**/*.md" ${writeLog(markdownLintFullLog)}` commands.markdownlintSrcFix = `${commands.markdownlintSrcSlim} ${and} ${commands.createFullMarkdownlintConfig} && ${execPath}/markdownlint-cli2-fix "${src}/**/*.md" ${writeLog(markdownLintFullLog)}` + commands.markdownlintSrcTypograph = `${commands.createTypographMarkdownlintConfig} && ${execPath}/markdownlint-cli2-fix "${src}/**/*.md" ${writeLog(markdownLintFullLog)}` commands.markdownlinkcheckSrcUnix = `find ${src}/ -type f -name '*.md' -print0 | xargs -0 -n1 ${execPath}/markdown-link-check -p -c ${path.join(__dirname, '/configs/mdLinkCheckConfig.json')} ${writeLog(path.join(cwd, markdownLinkCheckLog))}` commands.markdownlinkcheckSrcWin = `del ${path.join(cwd, markdownLinkCheckLog)} & forfiles /P ${src} /S /M *.md /C "cmd /c npx markdown-link-check @file -p -c ${path.join(__dirname, '/configs/mdLinkCheckConfig.json')} ${writeLog(path.join(cwd, markdownLinkCheckLog))}"` commands.markdownlinkcheckSrc = (isWin === true) ? commands.markdownlinkcheckSrcWin : commands.markdownlinkcheckSrcUnix @@ -294,6 +296,19 @@ program.command('fix') execute(commandsGen(options.source, options.config, options.project).commands.markdownlintSrcFix, options.verbose, options.debug, options.allowfailure, options.clearconfig) }) +program.command('typograph') + .description('Fix typographic errors with markdownlint') + .addOption(verboseOption) + .addOption(sourceOption) + .addOption(configOption) + .addOption(projectOption) + .addOption(debugOption) + .addOption(allowfailureOption) + .addOption(clearconfigOption) + .action((options) => { + execute(commandsGen(options.source, options.config, options.project).commands.markdownlintSrcTypograph, options.verbose, options.debug, options.allowfailure, options.clearconfig) + }) + program.command('print') .description('Print linting results') .addOption(verboseOption) @@ -319,4 +334,13 @@ program.command('create-slim-config') execute(commandsGen(options.source, options.config, options.project).commands.createSlimMarkdownlintConfig, options.verbose, options.debug) }) +program.command('create-typograph-config') + .description('Create typograph markdownlint config') + .addOption(sourceOption) + .addOption(projectOption) + .addOption(debugOption) + .action((options) => { + execute(commandsGen(options.source, options.config, options.project).commands.createTypographMarkdownlintConfig, options.verbose, options.debug) + }) + program.parse() diff --git a/package.json b/package.json index 015231e..2c88544 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foliant-md-linter", - "version": "0.1.8", + "version": "0.1.9", "description": "CLI tool for linting Foliant markdown sources", "license": "MIT", "homepage": "https://github.com/holamgadol/foliant-md-linter", @@ -22,7 +22,7 @@ "commander": "^10.0.0", "markdown-link-check": "^3.10.3", "markdownlint-cli2": "^0.6.0", - "markdownlint-rules-foliant": "^0.1.8" + "markdownlint-rules-foliant": "^0.1.9" }, "devDependencies": { "eslint": "^7.32.0", diff --git a/test/linter.spec.js b/test/linter.spec.js index 6de9cd0..5fd1df5 100644 --- a/test/linter.spec.js +++ b/test/linter.spec.js @@ -44,7 +44,7 @@ test('First print', async () => { }) test('create-full-config', async () => { - const expectedStdout = ['Command completed with no errors!\n'] + const expectedStdout = [''] const result = await cli(['create-full-config'], '.') expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(true) console.log(result) @@ -54,7 +54,7 @@ test('create-full-config', async () => { }) test('create-slim-config', async () => { - const expectedStdout = ['Command completed with no errors!\n'] + const expectedStdout = [''] const result = await cli(['create-slim-config'], '.') expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(true) console.log(result) @@ -63,6 +63,16 @@ test('create-slim-config', async () => { expect(result.code).toEqual(0) }) +test('create-typograph-config', async () => { + const expectedStdout = [''] + const result = await cli(['create-typograph-config'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(true) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + test('slim', async () => { const expectedStdout = [ 'Checked 2 files\n', @@ -634,6 +644,111 @@ test('fix -v -c -s no-errors-src -f', async () => { expect(result.code).toEqual(0) }) +test('typograph', async () => { + const expectedStdout = [ + 'Checked 2 files\n', + 'Found 0 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`] + const result = await cli(['typograph'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(true) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + +test('typograph -l', async () => { + const expectedStdout = [ + 'Checked 2 files\n', + 'Found 0 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`, + `removing ${path.join(cwd, '.markdownlint-cli2.jsonc ...')}`] + const result = await cli(['typograph', '-l'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(false) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + +test('typograph -v', async () => { + const expectedStdout = [ + 'Checked 2 files\n', + 'Found 0 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`] + const result = await cli(['typograph', '-v'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(true) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + +test('typograph -v -p another-project', async () => { + const expectedStdout = [ + 'Checked 2 files\n', + 'Found 0 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`] + const result = await cli(['typograph', '-v', '-p another-project'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(true) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + +test('typograph -v -c', async () => { + const expectedStdout = [ + 'Checked 2 files\n', + 'Found 3 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`] + const result = await cli(['typograph', '-v', '-c'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(false) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + +test('typograph -v -c -s alt-src', async () => { + const expectedStdout = [ + 'Checked 1 files\n', + 'Found 2 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`] + const result = await cli(['typograph', '-v', '-c', '-s alt-src'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(false) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + +test('typograph -v -c -s alt-src -f', async () => { + const expectedStdout = [ + 'Checked 1 files\n', + 'Found 2 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`] + const result = await cli(['typograph', '-v', '-c', '-s alt-src', '-f'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(false) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(1) +}) + +test('typograph -v -c -s no-errors-src -f', async () => { + const expectedStdout = [ + 'Checked 1 files\n', + 'Found 0 styleguide and formatting errors\n', + `Full markdownlint log see in ${path.join(cwd, '.markdownlint_full.log')}\n`] + const result = await cli(['typograph', '-v', '-c', '-s no-errors-src', '-f'], '.') + expect(fs.existsSync(`${cwd}/.markdownlint-cli2.jsonc`)).toBe(false) + console.log(result) + + expectedStdout.forEach(element => expect(result.stdout).toContain(element)) + expect(result.code).toEqual(0) +}) + test('urls', async () => { const expectedStdout = [ 'Found 2 broken external links\n',