Skip to content

Commit

Permalink
Merge "space" config
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jun 6, 2024
1 parent c8324a5 commit 231be9a
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 28 deletions.
36 changes: 18 additions & 18 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import globals from 'globals';
import confusingBrowserGlobals from 'confusing-browser-globals';
import eslintConfigXo from './index.js';

const [nodeConfig] = eslintConfigXo;
const [config] = eslintConfigXo;

const config = {
...nodeConfig,
languageOptions: {
...nodeConfig.languageOptions,
globals: {
...globals.es2021,
...globals.browser,
export default [
{
...config,
languageOptions: {
...config.languageOptions,
globals: {
...globals.es2021,
...globals.browser,
},
},
rules: {
...config.rules,
'no-restricted-globals': [
'error',
...confusingBrowserGlobals,
],
},
},
rules: {
...nodeConfig.rules,
'no-restricted-globals': [
'error',
...confusingBrowserGlobals,
],
},
};

export default [config];
];
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"type": "module",
"exports": {
".": "./index.js",
"./browser": "./browser.js"
"./browser": "./browser.js",
"./space": "./space.js",
"./space/browser": "./space-browser.js"
},
"repository": "xojs/eslint-config-xo",
"funding": "https://github.com/sponsors/sindresorhus",
Expand All @@ -24,7 +26,9 @@
},
"files": [
"index.js",
"browser.js"
"browser.js",
"space.js",
"space-browser.js"
],
"keywords": [
"eslintconfig",
Expand Down
21 changes: 20 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default [
];
```


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

```js
Expand All @@ -37,6 +36,26 @@ export default [
];
```

This package also exposes [`eslint-config-xo/space`](space.js) if you're in favor of 2-space indent:

```js
import eslintConfigXoSpace from 'eslint-config-xo/space';

export default [
...eslintConfigXoSpace,
];
```

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

```js
import eslintConfigXoSpaceBrowser from 'eslint-config-xo/space/browser';

export default [
...eslintConfigXoSpaceBrowser,
];
```

## Use the XO CLI instead

XO is an ESLint wrapper with great defaults.
Expand Down
19 changes: 19 additions & 0 deletions space-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import eslintConfigXoBrowser from './browser.js';

const [config] = eslintConfigXoBrowser;

export default [
{
...config,
rules: {
...config.rules,
indent: [
'error',
2,
{
SwitchCase: 1,
},
],
},
},
];
19 changes: 19 additions & 0 deletions space.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import eslintConfigXo from './index.js';

const [config] = eslintConfigXo;

export default [
{
...config,
rules: {
...config.rules,
indent: [
'error',
2,
{
SwitchCase: 1,
},
],
},
},
];
56 changes: 49 additions & 7 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import test from 'ava';
import {ESLint} from 'eslint';
import eslintConfigXoNode from '../index.js';
import eslintConfigXoBrowser from '../browser.js';
import eslintConfigXoSpaceNode from '../space.js';
import eslintConfigXoSpaceBrowser from '../space-browser.js';

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

Expand All @@ -16,16 +18,56 @@ async function runEslint(string, config) {
return firstResult.messages;
}

test('main', async t => {
t.true(Array.isArray(eslintConfigXoNode));
test('node', async t => {
for (const config of [eslintConfigXoNode, eslintConfigXoSpaceNode]) {
t.true(Array.isArray(config));

const errors = await runEslint('\'use strict\';\nconsole.log("unicorn")\n', eslintConfigXoNode);
t.true(hasRule(errors, 'quotes'), JSON.stringify(errors));
// eslint-disable-next-line no-await-in-loop
const errors = await runEslint('\'use strict\';\nconsole.log("unicorn")\n', config);
t.true(hasRule(errors, 'quotes'), JSON.stringify(errors));
}
});

test('browser', async t => {
t.true(Array.isArray(eslintConfigXoBrowser));
for (const config of [eslintConfigXoBrowser, eslintConfigXoSpaceBrowser]) {
t.true(Array.isArray(config));

const errors = await runEslint('\'use strict\';\nprocess.exit();\n', eslintConfigXoBrowser);
t.true(hasRule(errors, 'no-undef'), JSON.stringify(errors));
// eslint-disable-next-line no-await-in-loop
const errors = await runEslint('\'use strict\';\nprocess.exit();\n', config);
t.true(hasRule(errors, 'no-undef'), JSON.stringify(errors));
}
});

test('space', async t => {
const fixture = `
export function foo() {
\treturn true;
}
`.trim();

for (const {
expected,
config,
} of [
{
config: eslintConfigXoSpaceNode,
expected: true,
},
{
config: eslintConfigXoSpaceBrowser,
expected: true,
},
{
config: eslintConfigXoNode,
expected: false,
},
{
config: eslintConfigXoBrowser,
expected: false,
},
]) {
// eslint-disable-next-line no-await-in-loop
const errors = await runEslint(fixture, config);
t.is(hasRule(errors, 'indent'), expected, JSON.stringify(errors));
}
});

0 comments on commit 231be9a

Please sign in to comment.