Skip to content

Commit

Permalink
use root to find configuration of toml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Wilking committed Feb 19, 2024
1 parent 400e3c4 commit ae3615b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Because this option makes changes to the input files, it is good to make a backu

`markdownlint-cli` reuses [the rules][rules] from `markdownlint` package.

Configuration is stored in JSON, JSONC, YAML, or INI files in the same [config format][config]. Further, configuration can be stored as TOML file under ```[tool.markdownlint]```
Configuration is stored in JSON, JSONC, YAML, INI, or TOML files in the same [config format][config].

A sample configuration file:

Expand All @@ -103,7 +103,6 @@ A sample configuration file:
```

```toml
[tool.markdownlint]
default = true
heading-style = { style = "atx_closed" }
ul-indent = { indent = 4 }
Expand All @@ -127,8 +126,6 @@ If a rule is passed to both `--enable` and `--disable`, it will be disabled.

> JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
> TOML configuration files must be provided via the `--config` argument; they are not automatically loaded.
## Exit codes

`markdownlint-cli` returns one of the following exit codes:
Expand Down
5 changes: 3 additions & 2 deletions markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function yamlParse(text) {
}

function tomlParse(text) {
return require('toml').parse(text).tool.markdownlint;
return require('toml').parse(text);
}

const exitCodes = {
Expand All @@ -47,7 +47,7 @@ const exitCodes = {
unexpectedError: 4
};

const projectConfigFiles = ['.markdownlint.jsonc', '.markdownlint.json', '.markdownlint.yaml', '.markdownlint.yml'];
const projectConfigFiles = ['.markdownlint.jsonc', '.markdownlint.json', '.markdownlint.yaml', '.markdownlint.yml', '.markdownlint.toml'];
const configParsers = [jsoncParse, yamlParse, tomlParse];
const fsOptions = {encoding: 'utf8'};
const processCwd = process.cwd();
Expand All @@ -57,6 +57,7 @@ function readConfiguration(userConfigFile) {

// Load from well-known config files
let config = rc('markdownlint', {});

for (const projectConfigFile of projectConfigFiles) {
try {
fs.accessSync(projectConfigFile, fs.R_OK);
Expand Down
2 changes: 2 additions & 0 deletions test/config-files/toml/.markdownlint.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[no-trailing-punctuation]
punctuation="$"
3 changes: 3 additions & 0 deletions test/config-files/toml/heading-dollar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Heading$

Text
1 change: 0 additions & 1 deletion test/md043-config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[tool.markdownlint]
MD012 = false
MD043 = { headings = ["# First", "## Second", "### Third"] }
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ test('.markdownlint.jsonc in cwd is used automatically', getCwdConfigFileTest('j

test('.markdownlint.json in cwd is used automatically', getCwdConfigFileTest('json'));

test('.markdownlint.toml in cwd is used automatically', getCwdConfigFileTest('toml'));

test('.markdownlint.yaml in cwd is used automatically', getCwdConfigFileTest('yaml'));

test('.markdownlint.yml in cwd is used automatically', getCwdConfigFileTest('yml'));
Expand Down

0 comments on commit ae3615b

Please sign in to comment.