diff --git a/.changeset/swift-pugs-matter.md b/.changeset/swift-pugs-matter.md new file mode 100644 index 0000000000..2edd182b00 --- /dev/null +++ b/.changeset/swift-pugs-matter.md @@ -0,0 +1,5 @@ +--- +"stylelint": minor +--- + +Added: support for `.mjs` configuration files diff --git a/docs/user-guide/configure.md b/docs/user-guide/configure.md index 0a26ea4d9c..c1ed3cab73 100644 --- a/docs/user-guide/configure.md +++ b/docs/user-guide/configure.md @@ -5,7 +5,7 @@ Stylelint expects a configuration object, and looks for one in a: - `stylelint` property in `package.json` - `.stylelintrc` file - `.stylelintrc.{cjs,js,json,yaml,yml}` file -- `stylelint.config.{cjs,js}` file exporting a JS object +- `stylelint.config.{cjs,mjs,js}` file Starting from the current working directory, Stylelint stops searching when one of these is found. Alternatively, you can use the [`--config` or `configFile` option](options.md#configfile) to short-circuit the search. diff --git a/lib/__tests__/__snapshots__/cli.test.js.snap b/lib/__tests__/__snapshots__/cli.test.js.snap index 20f0226ade..3f7fdf2bef 100644 --- a/lib/__tests__/__snapshots__/cli.test.js.snap +++ b/lib/__tests__/__snapshots__/cli.test.js.snap @@ -16,15 +16,15 @@ exports[`CLI --help 1`] = ` --config, -c - A path to a specific configuration file (JSON, YAML, or CommonJS), or a - module name in "node_modules" that points to one. If no argument is + A path to a specific configuration file (JSON, YAML, CommonJS, or ES module), + or a module name in "node_modules" that points to one. If no argument is provided, Stylelint will search for configuration files in the following places, in this order: - a "stylelint" property in "package.json" - - a ".stylelintrc" file (with or without filename extension: - ".json", ".yaml", ".yml", ".js", and ".cjs" are available) - - a "stylelint.config.js" file exporting a JS object + - a ".stylelintrc" file + - a ".stylelintrc.{cjs,mjs,js,json,yaml,yml}" file + - a "stylelint.config.{cjs,mjs,js}" file The search will begin in the working directory and move up the directory tree until a configuration file is found. diff --git a/lib/cli.js b/lib/cli.js index 8845d1b6db..222a20d17d 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -107,15 +107,15 @@ const meowOptions = { --config, -c - A path to a specific configuration file (JSON, YAML, or CommonJS), or a - module name in "node_modules" that points to one. If no argument is + A path to a specific configuration file (JSON, YAML, CommonJS, or ES module), + or a module name in "node_modules" that points to one. If no argument is provided, Stylelint will search for configuration files in the following places, in this order: - a "stylelint" property in "package.json" - - a ".stylelintrc" file (with or without filename extension: - ".json", ".yaml", ".yml", ".js", and ".cjs" are available) - - a "stylelint.config.js" file exporting a JS object + - a ".stylelintrc" file + - a ".stylelintrc.{cjs,mjs,js,json,yaml,yml}" file + - a "stylelint.config.{cjs,mjs,js}" file The search will begin in the working directory and move up the directory tree until a configuration file is found. diff --git a/scripts/visual-config.cjs b/scripts/visual-config.cjs new file mode 100644 index 0000000000..c9f13a8d34 --- /dev/null +++ b/scripts/visual-config.cjs @@ -0,0 +1,5 @@ +'use strict'; + +const config = require('./visual-config.json'); + +module.exports = config; diff --git a/scripts/visual-config.mjs b/scripts/visual-config.mjs new file mode 100644 index 0000000000..0631acca63 --- /dev/null +++ b/scripts/visual-config.mjs @@ -0,0 +1,3 @@ +import config from './visual-config.cjs'; + +export default config; diff --git a/scripts/visual.sh b/scripts/visual.sh index 403bdec4c4..1ba34c8fb0 100755 --- a/scripts/visual.sh +++ b/scripts/visual.sh @@ -1,7 +1,14 @@ #!/usr/bin/env bash +set -u -echo "Normal:" -node ../bin/stylelint.js visual.css --config=visual-config.json +echo "########## Compact formatter ##########" +echo "" +node ../bin/stylelint.js visual.css --config visual-config.mjs --formatter compact +echo "" -echo -e "\n\nVerbose:" -node ../bin/stylelint.js visual.css --config=visual-config.json --formatter verbose +echo "" +echo "########## Default formatter ##########" +node ../bin/stylelint.js visual.css --config visual-config.json + +echo "########## Verbose formatter ##########" +node ../bin/stylelint.js visual.css --config visual-config.cjs --formatter verbose