Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson authored Jan 3, 2022
1 parent 597663a commit 0cfb7d0
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions markdownlint-cli2.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ const requireConfig = (fs, dir, name, noRequire) => (
)
);

// Read an options or config file in any format and return the object
const readOptionsOrConfig = async (pathSystem, dirSystem, fs, noRequire) => {
const name = path.basename(pathSystem);
let options = null;
let config = null;
if (name.endsWith(".markdownlint-cli2.jsonc")) {
options = jsoncParse(await fs.promises.readFile(pathSystem, utf8));
} else if (name.endsWith(".markdownlint-cli2.yaml")) {
options = yamlParse(await fs.promises.readFile(pathSystem, utf8));
} else if (name.endsWith(".markdownlint-cli2.js")) {
options = requireConfig(fs, dirSystem, ".markdownlint-cli2.js", noRequire);
} else if (
name.endsWith(".markdownlint.jsonc") ||
name.endsWith(".markdownlint.json") ||
name.endsWith(".markdownlint.yaml") ||
name.endsWith(".markdownlint.yml")
) {
config =
await markdownlintReadConfig(pathSystem, [ jsoncParse, yamlParse ], fs);
} else if (name.endsWith(".markdownlint.js")) {
config = requireConfig(fs, dirSystem, ".markdownlint.js", noRequire);
}
return options || { config };
};

// Filter a list of files to ignore by glob
const removeIgnoredFiles = (dir, files, ignores) => {
const micromatch = require("micromatch");
Expand Down Expand Up @@ -694,17 +719,21 @@ const main = async (params) => {
// eslint-disable-next-line max-len
`${name || packageName} v${packageVersion} (${libraryName} v${libraryVersion})`
);

// TBD -config

// Read argv configuration file (if relevant and present)
let optionsArgv = null;
const [ configPath ] = (argv || []);
if ((name === "markdownlint-cli2-config") && configPath) {
optionsArgv =
await readOptionsOrConfig(configPath, baseDirSystem, fs, noRequire);
}
// Process arguments and get base options
const globPatterns = processArgv(argv);
const globPatterns = processArgv(optionsArgv ? argv.slice(1) : argv);
const { baseMarkdownlintOptions, dirToDirInfo } =
await getBaseOptions(
fs,
baseDir,
globPatterns,
optionsDefault,
optionsArgv || optionsDefault,
fixDefault,
noGlobs,
noRequire
Expand Down

0 comments on commit 0cfb7d0

Please sign in to comment.