Skip to content
Merged
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
4 changes: 1 addition & 3 deletions packages/eslint-config-base/legacy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { FlatCompat } from '@eslint/eslintrc';
import { fixupConfigRules } from '@eslint/compat';

const compat = new FlatCompat({
baseDirectory: __dirname,
});
const compat = new FlatCompat();

export default [
...fixupConfigRules(compat.extends('eslint-config-airbnb-base/legacy')),
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-config-base/whitespace.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { FlatCompat } from '@eslint/eslintrc';
import { fixupConfigRules } from '@eslint/compat';

const compat = new FlatCompat({
baseDirectory: __dirname,
});
const compat = new FlatCompat();

export default [
...fixupConfigRules(compat.extends('eslint-config-airbnb-base/whitespace')),
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config-jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default [
jest.configs['flat/style'],
...fixupPluginRules(compat.extends('plugin:jest-formatting/recommended')),
{
name: '@alma-oss/eslint-config-jest',
files: [...globs.tests, 'config/jest/**'],

plugins: { jest },
Expand Down
40 changes: 29 additions & 11 deletions packages/eslint-config-react/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# @alma-oss/eslint-config-react

> Alma’s ESLint configuration for React projects
> ESLint configuration for React projects

## Installation
## 📦 Installation

```sh
npm install --save-dev eslint @alma-oss/eslint-config-react
# or
yarn add --dev eslint @alma-oss/eslint-config-react
```

Wee need to install everything needed by the config using (installs package and also peer dependencies):

Expand All @@ -12,28 +18,31 @@ npx install-peerdeps --dev @alma-oss/eslint-config-react

You can see in your package.json there is now a big list of devDependencies.

## Configurations
## 🧩 Rulesets

- **`@alma-oss/eslint-config-react`**

Use this ruleset to configure ESLint to work with React code.
A generic ruleset that focuses on code correctness.

- **`@alma-oss/eslint-config-react/optional`**

Use this ruleset together with the above ruleset. Provides additional insights into potential inconsistencies in the project.
Additional ruleset that might provide useful tips and hints how to improve your code.

> For new projects, it is recommended to enable this ruleset. For existing projects, it is only recommended for the brave.

## Recommended ESLint Configuration
## 👨‍💻 Usage

```js
// eslint.config.mjs
// eslint.config.js

import { defineConfig } from 'eslint/config';
import base from '@alma-oss/eslint-config-react';
import react from '@alma-oss/eslint-config-react';
import optional from '@alma-oss/eslint-config-react/optional';

export default defineConfig([...base, ...optional]);
export default defineConfig({
...react,
...optional,
});
```

It is also recommended that you lint the whole project folder (that is `npx eslint .`) instead of just
Expand Down Expand Up @@ -64,6 +73,15 @@ export default defineConfig({
});
```

## License
## 🙌 Contributing

We’re always looking for contributors to help us fix bugs, build new features,
or help us improve the project documentation. If you’re interested, definitely
check out our [Contributing Guide][contributing]! 👀

## 📝 License

Licensed under the [MIT][license].

See the [LICENSE](LICENSE) file for information.
[contributing]: https://github.com/lmc-eu/code-quality-tools/blob/main/CONTRIBUTING.md
[license]: https://github.com/lmc-eu/code-quality-tools/blob/main/LICENSE.md
1 change: 1 addition & 0 deletions packages/eslint-config-react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default [
reactA11y,
reactHooks,
{
name: '@alma-oss/eslint-config-react',
languageOptions: {
parser: babelParser,
parserOptions: {
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-config-react/rules/react-a11y.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat({
baseDirectory: __dirname,
});
const compat = new FlatCompat();

export default {
extends: compat.extends('eslint-config-airbnb/rules/react-a11y'),
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-config-react/rules/react-hooks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat({
baseDirectory: __dirname,
});
const compat = new FlatCompat();

export default {
extends: compat.extends('eslint-config-airbnb/rules/react-hooks'),
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-config-react/rules/react.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat({
baseDirectory: __dirname,
});
const compat = new FlatCompat();

export default {
extends: compat.extends('eslint-config-airbnb/rules/react'),
Expand Down
7 changes: 3 additions & 4 deletions packages/eslint-config-react/whitespace.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat({
baseDirectory: __dirname,
});
const compat = new FlatCompat();

export default [
...compat.extends('eslint-config-airbnb/whitespace'),
{
extends: compat.extends('eslint-config-airbnb/whitespace'),
name: '@alma-oss/eslint-config-react/whitespace',
rules: {},
},
];
99 changes: 46 additions & 53 deletions packages/eslint-config-typescript/README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,50 @@
# @alma-oss/eslint-config-typescript

These configuration files are suitable to lint TypeScript code.
> ESLint configuration for TypeScript projects

## Setup
## 📦 Installation

To lint TypeScript files using ESLint and this ruleset you must

1. Install ESLint & this ruleset
1. Tell the TypeScript parser where your _tsconfig.json_ file is (not doing so will cause some TS-syntax-specific rules to not work at all)
1. Extend one or more of the included rulesets

See the example _.eslintrc.js_ file below for more details and make sure you read the [Parser’s docs][ts-parser-configuration] about its settings.
```sh
npm install --save-dev eslint @alma-oss/eslint-config-typescript
# or
yarn add --dev eslint @alma-oss/eslint-config-typescript
```

## Configurations
## 🧩 Rulesets

- **`@alma-oss/eslint-config-typescript`**

Suitable for linting TypeScript source files.

Together with this ruleset, you should also choose one base ruleset depending on your target platform:
A generic ruleset that focuses on code correctness.

- [`@alma-oss/eslint-config-node`][eslint-config-node]
- [`@alma-oss/eslint-config-react`][eslint-config-react]
- **`@alma-oss/eslint-config-typescript/optional`**

### `@alma-oss/eslint-config-typescript/react`
Additional ruleset that might provide useful tips and hints how to improve your code.

React specific overrides.

## Optional Configurations

### `@alma-oss/eslint-config-typescript/optional`
> For new projects, it is recommended to enable this ruleset. For existing projects, it is only recommended for the brave.

Use this ruleset together with any of the above version-specific rulesets. Provides additional insights into potential inconsistencies in the project.
- **`@alma-oss/eslint-config-typescript/style`**

> For new projects, it is recommended to enable this ruleset. For existing projects, it is only recommended for the brave.
Ruleset that focuses on code style (indentation, spacing, naming, syntax preference etc.).

## Coding Styles
- **`@alma-oss/eslint-config-typescript/react`**

### `@alma-oss/eslint-config-typescript/style`
Ruleset that provides additional customizations for the `@alma-oss/eslint-config-react` ruleset when working with TypeScript.

This ruleset includes rules which deal with how the code looks like and not how it works. It helps keeping the code clean and consistent. 🎨
## 👨‍💻 Usage

A full configuration for a TypeScript on Node.js project:

```js
// eslint.config.js
import { defineConfig } from 'eslint/config';
import typescript from '@alma-oss/eslint-config-typescript';
import optional from '@alma-oss/eslint-config-typescript/optional';
import style from '@alma-oss/eslint-config-typescript/style';

/** @type {Array<import("eslint").Linter.Config>} */
export default defineConfig({
extends: [
'@alma-oss/eslint-config-node/v10',
'@alma-oss/eslint-config-node/optional',
'@alma-oss/eslint-config-typescript',
'@alma-oss/eslint-config-typescript/style',
],
...typescript,
...optional,
...style,

parserOptions: {
// The project field is required in order for some TS-syntax-specific rules to function at all
Expand All @@ -70,21 +61,17 @@ A full configuration for a TypeScript on React project:
```js
// eslint.config.mjs
import { defineConfig, globalIgnores } from 'eslint/config';
import { FlatCompat } from '@eslint/eslintrc';
import react from '@alma-oss/eslint-config-react';
import reactOptional from '@alma-oss/eslint-config-react/optional';
import ts from '@alma-oss/eslint-config-typescript';
import tsReact from '@alma-oss/eslint-config-typescript/react';

const compat = new FlatCompat({
baseDirectory: import.meta.dirname,
});
import typescript from '@alma-oss/eslint-config-typescript';
import react from '@alma-oss/eslint-config-typescript/react';
import optional from '@alma-oss/eslint-config-typescript/optional';
import style from '@alma-oss/eslint-config-typescript/style';

export default defineConfig([
...typescript,
...react,
...reactOptional,
...ts,
...tsReact,
...optional,
...style,

{
parserOptions: {
// The project field is required in order for some TS-syntax-specific rules to function at all
Expand All @@ -95,13 +82,9 @@ export default defineConfig([
]);
```

To actually lint .ts files, you must pass the `--ext` flag to ESLint:

```sh
eslint --ext ts --report-unused-disable-directives .
```
## 🔌 Integration

## VSCode integration
### Visual Studio Code

The [vscode-eslint](https://github.com/Microsoft/vscode-eslint) plugin for integrating ESLint into VSCode does not automatically parse TypeScript files. To do so, you must inform ESLint to enable on TypeScript files by adding this configuration to your settings (File > Preferences > Settings):

Expand All @@ -116,6 +99,16 @@ The [vscode-eslint](https://github.com/Microsoft/vscode-eslint) plugin for integ

> Notice we are adding `javascriptreact` and `typescriptreact` above. It won’t harm adding those, but you can always omit these languages if not using them.

[eslint-config-node]: https://www.npmjs.com/package/@alma-oss/eslint-config-node
## 🙌 Contributing

We’re always looking for contributors to help us fix bugs, build new features,
or help us improve the project documentation. If you’re interested, definitely
check out our [Contributing Guide][contributing]! 👀

## 📝 License

Licensed under the [MIT][license].

[eslint-config-react]: https://www.npmjs.com/package/@alma-oss/eslint-config-react
[ts-parser-configuration]: https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#configuration
[contributing]: https://github.com/lmc-eu/code-quality-tools/blob/main/CONTRIBUTING.md
[license]: https://github.com/lmc-eu/code-quality-tools/blob/main/LICENSE.md
1 change: 1 addition & 0 deletions packages/eslint-config-typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default [
...base,
tsEslint.configs.recommended,
{
name: '@alma-oss/eslint-config-typescript',
settings: {
// Correctly recognize .ts and .d.ts files when checking import paths against the filesystem
'import/resolver': {
Expand Down
14 changes: 13 additions & 1 deletion packages/eslint-config-typescript/optional.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import baseOptional from '@alma-oss/eslint-config-base/optional';

export default baseOptional;
export default [
...baseOptional,
{
name: '@alma-oss/eslint-config-typescript/optional',
rules: {
// TS code is mostly self-documented and having JSDoc directives for everything is redundant
// when you can easily infer return values and argument types from the code itself.
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/require-param-type': 'off',
},
},
];
5 changes: 5 additions & 0 deletions packages/eslint-config-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"url": "https://github.com/lmc-eu/code-quality-tools/issues"
},
"main": "index.js",
"exports": {
".": "./index.js",
"./react": "./react.js",
"./optional": "./optional.js"
},
"dependencies": {
"@alma-oss/eslint-config-base": "^4.0.0-alpha.0",
"@alma-oss/eslint-config-react": "^3.0.0-alpha.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-config-typescript/react.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import reactConfig from '@alma-oss/eslint-config-react';
import globs from '@alma-oss/eslint-config-base/globs';
// eslint-disable-next-line import/no-unresolved
import parser from '@typescript-eslint/parser';

export default [
...reactConfig,
{
name: '@alma-oss/eslint-config-typescript/react',
languageOptions: {
parser,
},
rules: {
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.jsx', '.ts', '.tsx'] }],
},
Expand Down