Skip to content

Commit 374dd73

Browse files
authored
Support xo.config.cjs and .xo-config.cjs (#561)
1 parent 3e7b77c commit 374dd73

File tree

8 files changed

+31
-1
lines changed

8 files changed

+31
-1
lines changed

lib/constants.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ const CONFIG_FILES = [
120120
`.${MODULE_NAME}-config`,
121121
`.${MODULE_NAME}-config.json`,
122122
`.${MODULE_NAME}-config.js`,
123-
`${MODULE_NAME}.config.js`
123+
`.${MODULE_NAME}-config.cjs`,
124+
`${MODULE_NAME}.config.js`,
125+
`${MODULE_NAME}.config.cjs`
124126
];
125127

126128
const TSCONFIG_DEFFAULTS = {

readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ module.exports = {
160160
};
161161
```
162162

163+
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`:
164+
165+
```js
166+
module.exports = {
167+
space: true
168+
};
169+
```
170+
163171
[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.
164172

165173
### envs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
space: true
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const object = {
2+
a: 1
3+
};
4+
5+
console.log(object.a);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const object = {
2+
a: 1
3+
};
4+
5+
console.log(object.a);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
space: true
3+
};

test/lint-files.js

+2
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ async function configType(t, {dir}) {
278278
configType.title = (_, {type}) => `load config from ${type}`.trim();
279279

280280
test(configType, {type: 'xo.config.js', dir: 'xo-config_js'});
281+
test(configType, {type: 'xo.config.cjs', dir: 'xo-config_cjs'});
281282
test(configType, {type: '.xo-config.js', dir: 'xo-config_js'});
283+
test(configType, {type: '.xo-config.cjs', dir: 'xo-config_cjs'});
282284
test(configType, {type: '.xo-config.json', dir: 'xo-config_json'});
283285
test(configType, {type: '.xo-config', dir: 'xo-config'});

test/lint-text.js

+2
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ async function configType(t, {dir}) {
324324
configType.title = (_, {type}) => `load config from ${type}`.trim();
325325

326326
test(configType, {type: 'xo.config.js', dir: 'xo-config_js'});
327+
test(configType, {type: 'xo.config.cjs', dir: 'xo-config_cjs'});
327328
test(configType, {type: '.xo-config.js', dir: 'xo-config_js'});
329+
test(configType, {type: '.xo-config.cjs', dir: 'xo-config_cjs'});
328330
test(configType, {type: '.xo-config.json', dir: 'xo-config_json'});
329331
test(configType, {type: '.xo-config', dir: 'xo-config'});

0 commit comments

Comments
 (0)