From 374dd734169c335c4c38fcbe848971bd037483f4 Mon Sep 17 00:00:00 2001 From: Joel Purra Date: Mon, 21 Jun 2021 11:30:30 +0200 Subject: [PATCH] Support `xo.config.cjs` and `.xo-config.cjs` (#561) --- lib/constants.js | 4 +++- readme.md | 8 ++++++++ test/fixtures/config-files/xo-config_cjs/.xo-config.cjs | 3 +++ test/fixtures/config-files/xo-config_cjs/file.js | 5 +++++ test/fixtures/config-files/xo_config_cjs/file.js | 5 +++++ test/fixtures/config-files/xo_config_cjs/xo.config.cjs | 3 +++ test/lint-files.js | 2 ++ test/lint-text.js | 2 ++ 8 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/config-files/xo-config_cjs/.xo-config.cjs create mode 100644 test/fixtures/config-files/xo-config_cjs/file.js create mode 100644 test/fixtures/config-files/xo_config_cjs/file.js create mode 100644 test/fixtures/config-files/xo_config_cjs/xo.config.cjs diff --git a/lib/constants.js b/lib/constants.js index aa3ce5fb..570f9016 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -120,7 +120,9 @@ const CONFIG_FILES = [ `.${MODULE_NAME}-config`, `.${MODULE_NAME}-config.json`, `.${MODULE_NAME}-config.js`, - `${MODULE_NAME}.config.js` + `.${MODULE_NAME}-config.cjs`, + `${MODULE_NAME}.config.js`, + `${MODULE_NAME}.config.cjs` ]; const TSCONFIG_DEFFAULTS = { diff --git a/readme.md b/readme.md index 5347b5aa..32cdba33 100644 --- a/readme.md +++ b/readme.md @@ -160,6 +160,14 @@ module.exports = { }; ``` +4. For [ECMAScript module (ESM)](https://nodejs.org/api/esm.html) packages with [`"type": "module"`](https://nodejs.org/api/packages.html#packages_type), as a JavaScript module in `.xo-config.cjs` or `xo.config.cjs`: + +```js +module.exports = { + space: true +}; +``` + [Globals](https://eslint.org/docs/user-guide/configuring#specifying-globals) and [rules](https://eslint.org/docs/user-guide/configuring#configuring-rules) can be configured inline in files. ### envs diff --git a/test/fixtures/config-files/xo-config_cjs/.xo-config.cjs b/test/fixtures/config-files/xo-config_cjs/.xo-config.cjs new file mode 100644 index 00000000..3c3e28a5 --- /dev/null +++ b/test/fixtures/config-files/xo-config_cjs/.xo-config.cjs @@ -0,0 +1,3 @@ +module.exports = { + space: true +}; diff --git a/test/fixtures/config-files/xo-config_cjs/file.js b/test/fixtures/config-files/xo-config_cjs/file.js new file mode 100644 index 00000000..eb542496 --- /dev/null +++ b/test/fixtures/config-files/xo-config_cjs/file.js @@ -0,0 +1,5 @@ +const object = { + a: 1 +}; + +console.log(object.a); diff --git a/test/fixtures/config-files/xo_config_cjs/file.js b/test/fixtures/config-files/xo_config_cjs/file.js new file mode 100644 index 00000000..eb542496 --- /dev/null +++ b/test/fixtures/config-files/xo_config_cjs/file.js @@ -0,0 +1,5 @@ +const object = { + a: 1 +}; + +console.log(object.a); diff --git a/test/fixtures/config-files/xo_config_cjs/xo.config.cjs b/test/fixtures/config-files/xo_config_cjs/xo.config.cjs new file mode 100644 index 00000000..3c3e28a5 --- /dev/null +++ b/test/fixtures/config-files/xo_config_cjs/xo.config.cjs @@ -0,0 +1,3 @@ +module.exports = { + space: true +}; diff --git a/test/lint-files.js b/test/lint-files.js index 5821b549..ab1144df 100644 --- a/test/lint-files.js +++ b/test/lint-files.js @@ -278,6 +278,8 @@ async function configType(t, {dir}) { configType.title = (_, {type}) => `load config from ${type}`.trim(); test(configType, {type: 'xo.config.js', dir: 'xo-config_js'}); +test(configType, {type: 'xo.config.cjs', dir: 'xo-config_cjs'}); test(configType, {type: '.xo-config.js', dir: 'xo-config_js'}); +test(configType, {type: '.xo-config.cjs', dir: 'xo-config_cjs'}); test(configType, {type: '.xo-config.json', dir: 'xo-config_json'}); test(configType, {type: '.xo-config', dir: 'xo-config'}); diff --git a/test/lint-text.js b/test/lint-text.js index 93312121..d365cfbb 100644 --- a/test/lint-text.js +++ b/test/lint-text.js @@ -324,6 +324,8 @@ async function configType(t, {dir}) { configType.title = (_, {type}) => `load config from ${type}`.trim(); test(configType, {type: 'xo.config.js', dir: 'xo-config_js'}); +test(configType, {type: 'xo.config.cjs', dir: 'xo-config_cjs'}); test(configType, {type: '.xo-config.js', dir: 'xo-config_js'}); +test(configType, {type: '.xo-config.cjs', dir: 'xo-config_cjs'}); test(configType, {type: '.xo-config.json', dir: 'xo-config_json'}); test(configType, {type: '.xo-config', dir: 'xo-config'});