Skip to content

Commit

Permalink
Support xo.config.cjs and .xo-config.cjs (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpurra committed Jun 21, 2021
1 parent 3e7b77c commit 374dd73
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/constants.js
Expand Up @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/config-files/xo-config_cjs/.xo-config.cjs
@@ -0,0 +1,3 @@
module.exports = {
space: true
};
5 changes: 5 additions & 0 deletions test/fixtures/config-files/xo-config_cjs/file.js
@@ -0,0 +1,5 @@
const object = {
a: 1
};

console.log(object.a);
5 changes: 5 additions & 0 deletions test/fixtures/config-files/xo_config_cjs/file.js
@@ -0,0 +1,5 @@
const object = {
a: 1
};

console.log(object.a);
3 changes: 3 additions & 0 deletions test/fixtures/config-files/xo_config_cjs/xo.config.cjs
@@ -0,0 +1,3 @@
module.exports = {
space: true
};
2 changes: 2 additions & 0 deletions test/lint-files.js
Expand Up @@ -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'});
2 changes: 2 additions & 0 deletions test/lint-text.js
Expand Up @@ -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'});

0 comments on commit 374dd73

Please sign in to comment.