diff --git a/cli.js b/cli.js index 3db54e1..487ece6 100644 --- a/cli.js +++ b/cli.js @@ -32,10 +32,13 @@ if (argv.help) { const cwd = process.cwd() const glob = argv._.length ? argv._ : ['*.md'] const pkg = getNearestPackage(cwd) || {} - const packageOpts = pkg.hallmark || {} + const packageOpts = Object.assign({}, pkg.hallmark) const repo = pkg.repository ? pkg.repository.url || pkg.repository : '' const ignore = [].concat(packageOpts.ignore || []).concat(argv.ignore || []) + packageOpts.validateLinks = packageOpts.validateLinks !== false + packageOpts.paddedTable = packageOpts.paddedTable !== false + deglob(glob, { usePackageJson: false, cwd, ignore }, function (err, files) { if (err) throw err if (files.length === 0) process.exit() diff --git a/lint.js b/lint.js index e254fc6..d28d2e8 100644 --- a/lint.js +++ b/lint.js @@ -1,4 +1,4 @@ -module.exports = function (fix, cwd, validateLinks, repository) { +module.exports = function (fix, cwd, packageOpts, repository) { const preset = { plugins: [ require('remark-lint'), @@ -30,7 +30,10 @@ module.exports = function (fix, cwd, validateLinks, repository) { require('remark-lint-no-heading-content-indent'), require('remark-lint-hard-break-spaces'), [require('remark-lint-code-block-style'), 'fenced'], - [require('remark-lint-table-cell-padding'), 'padded'], + + // TODO: support fixed-width columns (https://github.com/remarkjs/remark-lint/issues/217) + packageOpts.paddedTable ? [require('remark-lint-table-cell-padding'), 'padded'] : null, + require('remark-lint-table-pipes'), [require('remark-lint-checkbox-character-style'), { checked: 'x', unchecked: ' ' @@ -42,7 +45,7 @@ module.exports = function (fix, cwd, validateLinks, repository) { // Temporarily allow skipping link validation, because remark does not parse // HTML anchors - as used in various Level readme's. Those readme's should be // updated to use markdown only. - if (validateLinks) { + if (packageOpts.validateLinks) { preset.plugins.push([require('remark-validate-links'), { // If we don't pass this, remark-validate-links tries to get the repo url // from `git remote -v` which is not desirable for forks. @@ -50,5 +53,6 @@ module.exports = function (fix, cwd, validateLinks, repository) { }]) } + preset.plugins = preset.plugins.filter(Boolean) return preset } diff --git a/options.js b/options.js index 323386c..8bab330 100644 --- a/options.js +++ b/options.js @@ -42,12 +42,18 @@ module.exports = function (argv, packageOpts, files, cwd, repository) { test: /^table of contents$/i, summary: 'Click to expand' }], - require('./lint')(fix, cwd, packageOpts.validateLinks !== false, repository) + require('./lint')(fix, cwd, packageOpts, repository) ].filter(Boolean), settings: { // One style for code blocks, whether they have a language or not. fences: true, - listItemIndent: '1' + listItemIndent: '1', + + // Allow disabling padding because on big tables it creates noise. + paddedTable: packageOpts.paddedTable, + + // In addition, use fixed width columns. + stringLength: packageOpts.paddedTable ? (s) => String(s).length : () => 3 }, pluginPrefix: 'remark', // "Whether to write successfully processed files"