Skip to content

Commit

Permalink
Support .mjs configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Jun 8, 2023
1 parent 1e570f3 commit 329e847
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
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

0 comments on commit 329e847

Please sign in to comment.