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

Migrate to flat config #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';
import eslintConfigXoBrowser from 'eslint-config-xo/browser';

module.exports = {
extends: 'xo/browser',
export default {
...eslintConfigXoBrowser,
rules: {
...eslintConfigXoBrowser.rules,
indent: [
'error',
2,
{
SwitchCase: 1
}
]
}
},
};
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';
import eslintConfigXo from 'eslint-config-xo';

module.exports = {
extends: 'xo',
export default {
...eslintConfigXo,
rules: {
...eslintConfigXo.rules,
indent: [
'error',
2,
{
SwitchCase: 1
}
]
}
},
};
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"version": "0.35.0",
"description": "ESLint shareable config for XO with 2-space indent",
"license": "MIT",
"type": "module",
"exports": {
".": "./index.js",
"./browser": "./browser.js"
},
"repository": "xojs/eslint-config-xo-space",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
Expand All @@ -12,7 +17,7 @@
},
"sideEffects": false,
"engines": {
"node": ">=12"
"node": ">=18"
},
"scripts": {
"test": "ava"
Expand Down Expand Up @@ -49,12 +54,12 @@
"simple"
],
"dependencies": {
"eslint-config-xo": "^0.44.0"
"eslint-config-xo": "fisker/eslint-config-xo#flat-config"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need fix this before merge.

},
"devDependencies": {
"ava": "^2.4.0",
"eslint": "^8.56.0",
"is-plain-obj": "^3.0.0"
"ava": "^6.1.3",
"eslint": "^9.4.0",
"is-plain-obj": "^4.1.0"
},
"peerDependencies": {
"eslint": ">=8.56.0"
Expand Down
34 changes: 13 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,24 @@ npm install --save-dev eslint-config-xo-space

## Usage

Add some ESLint config to your `package.json`:

```json
{
"name": "my-awesome-project",
"eslintConfig": {
"extends": "xo-space"
}
}
```
Add some ESLint config to your `eslint.config.js`:

Or to `.eslintrc`:
```js
import eslintConfigXoSpace from 'eslint-config-xo-space';

```json
{
"extends": "xo-space"
}
export default [
eslintConfigXoSpace,
];
```

This package also exposes [`xo-space/browser`](browser.js) if you're in the browser:
This package also exposes [`eslint-config-xo-space/browser`](browser.js) if you're in the browser:

```json
{
"extends": "xo-space/browser"
}
```
```js
import eslintConfigXoSpaceBrowser from 'eslint-config-xo/browser';

export default [
eslintConfigXoSpaceBrowser,
];

## Related

Expand Down
20 changes: 9 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import test from 'ava';
import isPlainObj from 'is-plain-obj';
import {ESLint} from 'eslint';
import eslintConfigXoSpaceNode from '../index.js';
import eslintConfigXoSpaceBrowser from '../browser.js';

const hasRule = (errors, ruleId) => errors.some(error => error.ruleId === ruleId);

const fixture = `"use strict";\nconst x = true;\n\nif (x) {\n console.log();\n}\n`;

async function runEslint(string, config) {
const eslint = new ESLint({
useEslintrc: false,
overrideConfigFile: true,
overrideConfig: config,
});

Expand All @@ -18,21 +20,17 @@ async function runEslint(string, config) {
}

test('main', async t => {
const config = require('../index.js');
t.true(isPlainObj(eslintConfigXoSpaceNode));
t.true(isPlainObj(eslintConfigXoSpaceNode.rules));

t.true(isPlainObj(config));
t.true(isPlainObj(config.rules));

const errors = await runEslint(fixture, config);
const errors = await runEslint(fixture, eslintConfigXoSpaceNode);
t.true(hasRule(errors, 'quotes'), JSON.stringify(errors));
});

test('browser', async t => {
const config = require('../browser.js');

t.true(isPlainObj(config));
t.true(isPlainObj(config.rules));
t.true(isPlainObj(eslintConfigXoSpaceBrowser));
t.true(isPlainObj(eslintConfigXoSpaceBrowser.rules));

const errors = await runEslint(fixture, config);
const errors = await runEslint(fixture, eslintConfigXoSpaceBrowser);
t.true(hasRule(errors, 'quotes'), JSON.stringify(errors));
});