Skip to content

Commit

Permalink
Allow user configuration files to be YAML-formatted.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed May 29, 2018
1 parent 2cb6a75 commit 0da8b3a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $ markdownlint --help
-V, --version output the version number
-s, --stdin read from STDIN (no files)
-o, --output [outputFile] write issues to file (no console)
-c, --config [configFile] configuration file
-c, --config [configFile] configuration file (JSON or YAML)
-i, --ignore [file|directory|glob] files to ignore/exclude
```

Expand All @@ -47,7 +47,7 @@ The example of configuration file:

See [test configuration file][test-config] or [style folder][style-folder] for more examples.

CLI argument `--config` is not mandatory. If it is not provided, `markdownlint-cli` looks for file `.markdownlint.json` in current folder, or for file `.markdownlintrc` in current or all upper folders. The algorithm is described in details on [rc package page][rc-standards].
CLI argument `--config` is not mandatory. If it is not provided, `markdownlint-cli` looks for file `.markdownlint.json` in current folder, or for file `.markdownlintrc` in current or all upper folders. The algorithm is described in details on [rc package page][rc-standards]. If `--config` argument is provided, the file must be valid JSON or YAML.

## Related

Expand Down
5 changes: 3 additions & 2 deletions markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var fs = require('fs');
var path = require('path');
var program = require('commander');
var getStdin = require('get-stdin');
var jsYaml = require('js-yaml');
var differenceWith = require('lodash.differencewith');
var flatten = require('lodash.flatten');
var extend = require('deep-extend');
Expand All @@ -31,7 +32,7 @@ function readConfiguration(args) {
// from .markdownlint.json.
if (userConfigFile) {
try {
var userConfig = markdownlint.readConfigSync(userConfigFile);
var userConfig = markdownlint.readConfigSync(userConfigFile, [JSON.parse, jsYaml.safeLoad]);
config = extend(config, userConfig);
} catch (err) {
console.warn('Cannot read or parse config file', args.config);
Expand Down Expand Up @@ -115,7 +116,7 @@ program
.usage('[options] <files|directories|globs>')
.option('-s, --stdin', 'read from STDIN (no files)')
.option('-o, --output [outputFile]', 'write issues to file (no console)')
.option('-c, --config [configFile]', 'configuration file')
.option('-c, --config [configFile]', 'configuration file (JSON or YAML)')
.option('-i, --ignore [file|directory|glob]', 'files to ignore/exclude', concatArray, []);

program.parse(process.argv);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"deep-extend": "~0.5.1",
"get-stdin": "~5.0.1",
"glob": "~7.0.3",
"js-yaml": "~3.11.0",
"lodash.differencewith": "~4.5.0",
"lodash.flatten": "~4.4.0",
"markdownlint": "~0.10.0",
Expand Down
5 changes: 5 additions & 0 deletions test/md043-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MD043:
headers:
- "# First"
- "## Second"
- "### Third"
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,10 @@ test('--output with invalid path fails', async t => {
t.throws(() => fs.accessSync(output, 'utf8'), Error);
}
});

test('configuration file can be YAML', async t => {
const result = await execa('../markdownlint.js',
['--config', 'md043-config.yaml', 'md043-config.md']);
t.true(result.stdout === '');
t.true(result.stderr === '');
});

0 comments on commit 0da8b3a

Please sign in to comment.