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

BREAKING CHANGE: add eslint9 config files #125

Merged
merged 7 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
59 changes: 45 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,61 @@ npm install eslint-config-brightspace

## Usage

Set the `extends` property in the `.eslintrc.json` file, replacing `<environment>` with the desired environment-specific config.
To use a shared configuration without any customizations, export it from a `eslint.config.js` file at the project root:
```js
export { nodeConfig as default } from 'eslint-config-brightspace';
```

Shared configurations can also be included in a custom configuration:
```js
import { nodeConfig } from 'eslint-config-brightspace';

export default [
...nodeConfig,
// Custom configuration
];
```

### Additional File Extensions

Include extensions beyond `.js` files using the `addExtenstion` helper function:
```js
import { addExtensions, nodeConfig } from 'eslint-config-brightspace';
export default addExtensions(nodeConfig, ['.js','.html']);
```

### Different Configurations for Different Directories

To include different configurations for specific directories, use the `setDirectoryConfigs` helper function. This replaces the [configuration hierarchy](https://eslint.org/docs/v8.x/use/configure/configuration-files#cascading-and-hierarchy) from `eslint8`.

Include the global configuration and specify the directory configurations. These will apply to all files inside the directory and recursively to any of its subdirectories.
```js
import { litConfig, nodeConfig, setDirectoryConfigs, testingConfig } from 'eslint-config-brightspace';

```json
{
"extends": "brightspace/<environment>"
}
dlockhart marked this conversation as resolved.
Show resolved Hide resolved
export default setDirectoryConfigs(
litConfig,
{
'test': testingConfig,
'test/cli': nodeConfig
}
);
```
Note that each set configuration will force all prior configurations to ignore it. For example, for the above configuration, `litConfig` will ignore any files in the `test` directory; and `testingConfig` will ignore any files in the `test/cli` directory.

### Environment Specific Configs

| Environment | Description |
|--|--|
| `browser-config` | use with code that runs in a browser |
| `lit-config` | use with [Lit](https://lit.dev/) projects |
| `testing-config` | use with [@brightspace-ui/testing](https://github.com/BrightspaceUI/testing) test code |
| `node-config` | use with [Node.js](https://nodejs.org) projects |
| `react-config` | use with [React](https://react.dev/) projects |
| `browserConfig` | use with code that runs in a browser |
| `litConfig` | use with [Lit](https://lit.dev/) projects |
| `testingConfig` | use with [@brightspace-ui/testing](https://github.com/BrightspaceUI/testing) test code |
| `nodeConfig` | use with [Node.js](https://nodejs.org) projects |
| `reactConfig` | use with [React](https://react.dev/) projects |

Example:

```json
{
"extends": "brightspace/lit-config"
}
```js
export { nodeConfig as default } from 'eslint-config-brightspace';
```

See the [eslint rules](https://eslint.org/docs/latest/rules/) for more details on rule configuration. See the [eslint shareable configs](https://eslint.org/docs/latest/extend/shareable-configs.html) for more details on creating configs.
Expand Down
36 changes: 0 additions & 36 deletions browser-config.js

This file was deleted.

45 changes: 45 additions & 0 deletions configs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// nr = not as per eslint:recommended
import js from '@eslint/js';

export default [js.configs.recommended, {
'rules': {
'comma-spacing': 2, // nr
'eol-last': 2, // nr
'eqeqeq': [2, 'always', { 'null': 'ignore' }], // nr
'indent': [2, 'tab', { 'SwitchCase': 1 }], // nr
'keyword-spacing': 2,
'linebreak-style': ['error', 'unix'], // nr
'new-parens': 2, // nr
'no-debugger': 2,
'no-dupe-args': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-ex-assign': 2,
'no-fallthrough': 2,
'no-invalid-this': 2, // nr
'no-multiple-empty-lines': [2, { 'max': 1 }], // nr
'no-multi-spaces': 2, // nr
'no-new-wrappers': 2, // nr
'no-trailing-spaces': 2, // nr
'no-undef': 2,
'no-unneeded-ternary': 2, // nr
'no-unreachable': 2,
'no-unused-vars': [2, {
'vars': 'all',
'args': 'after-used',
'ignoreRestSiblings': true
}],
'no-use-before-define': [2, 'nofunc'], // nr
'no-var': 2, // nr
'object-curly-spacing': [2, 'always'],
'prefer-const': 2, // nr
'quotes': [2, 'single', 'avoid-escape'], // nr
'semi': 2, // nr
'space-before-blocks': [2, 'always'], // nr
'space-before-function-paren': [2, 'never'], //nr
'space-in-parens': [2, 'never'],
'space-infix-ops': 2, // nr
'strict': [2, 'global'], // nr
'valid-typeof': 2
}
}];
43 changes: 43 additions & 0 deletions configs/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import parser from '@babel/eslint-parser';
import globals from 'globals';
import baseConfig from './base.js';
import html from 'eslint-plugin-html';
import importPlugin from 'eslint-plugin-import';
import sortClassMembersPlugin from 'eslint-plugin-sort-class-members';
import { getSortMemberRules } from '../utils.js';

export default [
...baseConfig,
{
plugins: {
html,
'import': importPlugin,
'sort-class-members': sortClassMembersPlugin
},
languageOptions: {
parser,
parserOptions: {
'requireConfigFile': false
},
globals: {
...globals.browser,
'D2L': false
},
},
rules: {
'arrow-spacing': 2,
'no-confusing-arrow': 2,
'no-duplicate-imports': 2,
'no-useless-constructor': 2,
'prefer-arrow-callback': 2,
'prefer-spread': 2,
'prefer-template': 2,
'sort-imports': [2, { 'ignoreCase': true }],
'strict': [2, 'never'],
'import/extensions': ['error', 'ignorePackages'],
'import/no-absolute-path': 2,
'no-console': ['error', { 'allow': ['warn', 'error'] }],
...getSortMemberRules()
}
}
];
78 changes: 78 additions & 0 deletions configs/lit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import browserConfig from './browser.js';
import lit from 'eslint-plugin-lit';
import { getSortMemberRules } from '../utils.js';

const sortMemberRules = getSortMemberRules([
'[lit-static-properties]',
'[static-properties]',
'[static-methods]',
'[properties]',
'constructor',
'[accessor-pairs]',
'[accessors]',
'[lit-methods]',
'[methods]',
'[private-accessor-pairs]',
'[private-accessors]',
'[private-properties]',
'[private-methods]'
], {
'lit-methods': [
{ 'name': 'adoptedCallback', 'type': 'method' },
{ 'name': 'attributeChangedCallback', 'type': 'method' },
{ 'name': 'connectedCallback', 'type': 'method' },
{ 'name': 'disconnectedCallback', 'type': 'method' },
{ 'name': 'firstUpdated', 'type': 'method' },
{ 'name': 'getUpdateComplete', 'type': 'method' },
{ 'name': 'performUpdate', 'type': 'method' },
{ 'name': 'render', 'type': 'method' },
{ 'name': 'scheduleUpdate', 'type': 'method' },
{ 'name': 'shouldUpdate', 'type': 'method' },
{ 'name': 'update', 'type': 'method' },
{ 'name': 'updated', 'type': 'method' },
{ 'name': 'willUpdate', 'type': 'method' }
],
'lit-static-properties': [
{ 'name': 'properties', 'static': true },
{ 'name': 'styles', 'static': true }
]
});

export default [
...browserConfig,
{
plugins: { lit },
rules: {
'lit/attribute-value-entities': 2,
'lit/binding-positions': 2,
'lit/lifecycle-super': 2,
'lit/no-duplicate-template-bindings': 2,
'lit/no-invalid-escape-sequences': 2,
'lit/no-invalid-html': 2,
'lit/no-legacy-imports': 2,
'lit/no-legacy-template-syntax': 2,
'lit/no-private-properties': [2, { 'private': '^(__|_)' }],
'lit/no-property-change-update': 2,
'lit/no-native-attributes': 1,
'lit/no-template-arrow': 2,
'lit/no-template-bind': 2,
'lit/no-template-map': 0,
'lit/no-this-assign-in-render': 2,
'lit/no-useless-template-literals': 2,
'lit/no-value-attribute': 2,
'lit/prefer-nothing': 2,
...sortMemberRules
}
},
{
'files': ['./**/lang/*.js'],
'rules': {
'quotes': 0
}
}, {
'files': ['./**/demo/*.html'],
'rules': {
'no-console': 0
}
}
];
20 changes: 20 additions & 0 deletions configs/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import globals from 'globals';
import baseConfig from './base.js';

export default [
...baseConfig,
{
'languageOptions': {
'parserOptions': {
'sourceType': 'module'
},
'globals': {
...globals.node,
...globals.es2024
},
},
'rules': {
'no-console':0
}
}
];
25 changes: 25 additions & 0 deletions configs/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import globals from 'globals';
import baseConfig from './base.js';
import react from 'eslint-plugin-react';

export default [
...baseConfig,
{
'languageOptions': {
'parserOptions': {
'ecmaFeatures': {
'jsx': true
},
'sourceType': 'module'
},
'globals': {
...globals.browser,
...globals.es2015,
...globals.jest,
...globals.node,
},
'ecmaVersion': 6,
},
'plugins': { react }
}
];
16 changes: 16 additions & 0 deletions configs/testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import globals from 'globals';
import litConfig from './lit.js';

export default [
...litConfig,
{
'languageOptions': {
'globals': {
...globals.mocha,
}
},
'rules': {
'no-invalid-this': 0
}
}
];
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { nodeConfig as default } from './index.js';
Loading