Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .mjs configuration files #6910

Merged
merged 1 commit into from Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-pugs-matter.md
@@ -0,0 +1,5 @@
---
"stylelint": minor
---

Added: support for `.mjs` configuration files
2 changes: 1 addition & 1 deletion docs/user-guide/configure.md
Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions lib/__tests__/__snapshots__/cli.test.js.snap
Expand Up @@ -16,15 +16,15 @@ exports[`CLI --help 1`] = `

--config, -c <path_or_module>

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.
Expand Down
10 changes: 5 additions & 5 deletions lib/cli.js
Expand Up @@ -107,15 +107,15 @@ const meowOptions = {
--config, -c <path_or_module>
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.
Expand Down
5 changes: 5 additions & 0 deletions scripts/visual-config.cjs
@@ -0,0 +1,5 @@
'use strict';

const config = require('./visual-config.json');

module.exports = config;
3 changes: 3 additions & 0 deletions scripts/visual-config.mjs
@@ -0,0 +1,3 @@
import config from './visual-config.cjs';

export default config;
15 changes: 11 additions & 4 deletions 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