Skip to content

Convert to ESLint 9 flat config and move to pnpm #19

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

Merged
merged 5 commits into from
Oct 18, 2024
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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# These are org-wide files (https://github.com/exercism/org-wide-files/)
/.github/labels.yml
/.github/workflows/pause-community-contributions.yml
/.github/workflows/sync-labels.yml

/CODE_OF_CONDUCT.md
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.7.0

- Use pnpm 9.6.0
- Update to eslint 9+
- Migrate to flat config

## 0.6.0

- Upgrade to eslint 8+
Expand Down
56 changes: 40 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
# @exercism/eslint-config-javascript

This is the shared [`eslint`][web-eslint] configuration used by the [JavaScript track][git-javascript] (for students) and the files contributors and maintainers touch. [Shareable configs][web-shareable-configs] are designed to work with the `extends` feature of `.eslintrc` files. This means you can use the same configuration you're used to on [Exercism][web-exercism] in your on projects!
This is the shared [`eslint`][web-eslint] configuration used by the [JavaScript track][git-javascript] (for students) and the files contributors and maintainers touch.
[Shareable configs][web-shareable-configs] are designed to work with the `extends` feature of ESLint configuration files.
This means you can use the same configuration you're used to on [Exercism][web-exercism] in your on projects!

## Usage

To use the configuration for students, open your [eslint configuration][web-eslint-configuration] file, and add the following value to `extends`. For example, for JSON based configuration files:
To use the configuration for students, open your [eslint configuration][web-eslint-configuration] file, and import the following file for the flat config.
For example, for flat config configuration files:

```json
{
"extends": "@exercism/eslint-config-javascript"
}
```javascript
import baseConfig from '@exercism/eslint-config-javascript';

// ...
export default [
...baseConfig,
// ... your configuration
];
```

To use the configuration used by contributors and maintainers, add the following to `extends`:
To use the configuration used by contributors and maintainers, add the following:

```javascript
import baseConfig from '@exercism/eslint-config-javascript/maintainers';

```json
{
"extends": "@exercism/eslint-config-javascript/maintainers"
}
// ...
export default [
...baseConfig,
// ... your configuration
];
```

## Students configuration

Find the student configuration [here](index.js). It's goal is to help detect and prevent common problems, without making _any_ decisions about code-style.
Find the student configuration [here](index.mjs).
It's goal is to help detect and prevent common problems, without making _any_ decisions about code-style.

The rules are based on:

- [`eslint:recommended`][web-eslint-recommended]
- [`plugin:import`][git-eslint-plugin-import]
- A few extra rules that catch common issues but are not enabled via the recommended plugin. See [this PR][git-javascript-pr-1094] for a bit of discussion and rationale.

Because the [Exercism JavaScript track][git-javascript] is primarily focussing on running the exercises on Node, only `node` and `es2021` are turned on as environment, but when extending this configuration, you can add more (or turn those off).
Because the [Exercism JavaScript track][git-javascript] is primarily focussing on running the exercises on Node, only `node` globals are turned on in the environment, but when extending this configuration, you can add more (or turn those off).

## Maintainers configuration

Similar to the students configuration, and found [here](maintainers.js), it also includes the [`prettier` plugin][git-eslint-plugin-prettier] because we use [`prettier`][web-prettier] to achieve consistent code formatting. This plugin turns _off_ rules that conflict with formatting.
Similar to the students configuration, and found [here](maintainers.mjs), it also includes the [`prettier` plugin][git-eslint-plugin-prettier] because we use [`prettier`][web-prettier] to achieve consistent code formatting.
This plugin turns _off_ rules that conflict with formatting.

Additionally, it doesn't have warnings but errors for most/all of the rules in the students configuration.

## Tooling configuration

Because the tooling (such as the [JavaScript Analyzer][git-javascript-analyzer], [Representer][git-javascript-representer], and [Test Runner][git-javascript-test-runner]) are written in TypeScript, they don't use the same configuration files. If you're looking for those, or to build your own tools in TypeScript, go to [@exercism/eslint-config-tooling][git-eslint-config-tooling].
Because the tooling (such as the [JavaScript Analyzer][git-javascript-analyzer], [Representer][git-javascript-representer], and [Test Runner][git-javascript-test-runner]) are written in TypeScript, they don't use the same configuration files.
If you're looking for those, or to build your own tools in TypeScript, go to [@exercism/eslint-config-tooling][git-eslint-config-tooling].

## Development

If you want to work on this repository, install the dependencies using `corepack` and `pnpm`:

```shell
corepack enable pnpm
corepack pnpm install
```

Because pnpm is configured to use isolated `node_modules` (symlinked), everything such as your tools and plugins inside your editor should keep working as expected.

[git-eslint-config-tooling]: https://github.com/exercism/eslint-config-tooling
[git-eslint-plugin-import]: https://github.com/benmosher/eslint-plugin-import
Expand Down
4 changes: 4 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-javascript'],
plugins: [],
};
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import maintainers from './maintainers.mjs';

export default [
...maintainers,
{
ignores: [
'.appends/**/*',
'.github/**/*',
'.vscode/**/*',
'.yarn/**/*',
'.pnp.*',
],
},
];
41 changes: 0 additions & 41 deletions index.js

This file was deleted.

82 changes: 82 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import babelParser from '@babel/eslint-parser';
import fs from 'fs';

import eslint from '@eslint/js';
import jestPlugin from 'eslint-plugin-jest';
import prettierConfig from 'eslint-config-prettier';

import globals from 'globals';

const pkg = JSON.parse(
fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
);

/** @type {import('eslint').ESLint.Plugin} */
const plugin = {
meta: {
name: pkg.name + '/maintainers',
version: pkg.version,
},
};

/** @type {import('eslint').Linter.Config} */
export default [
{
...eslint.configs.recommended,
plugins: {
jest: jestPlugin,
[plugin.meta.name]: plugin,
},
languageOptions: {
parser: babelParser,
parserOptions: {
ecmaVersion: 'latest',
},
globals: {
...globals.node,
},
},

rules: {
...eslint.configs.recommended.rules,

// eslint rules
'array-callback-return': ['warn', { checkForEach: false }],
'default-param-last': 'error',
eqeqeq: ['warn', 'smart'],
'linebreak-style': 'off',
'no-eval': ['error', { allowIndirect: true }],
'no-extend-native': 'warn',
'no-implicit-coercion': 'warn',
'no-promise-executor-return': 'warn',
'no-shadow': 'warn',
'no-unreachable-loop': 'warn',
'no-unsafe-optional-chaining': 'error',
'require-atomic-updates': 'warn',
},
},

{
// enable jest rules on test files
files: ['test/**', '**/*.spec.js*', '**/*.test.js*'],
...jestPlugin.configs['flat/recommended'],
rules: {
...jestPlugin.configs['flat/recommended'].rules,
'jest/no-disabled-tests': 'off',
'jest/no-test-prefixes': 'off',
},
languageOptions: {
globals: {
// Don't make jest globals available! These should not be available
// but imported from @jest/globals.
//
// ...globals.jest,
},
},
},

// https://github.com/import-js/eslint-plugin-import/pull/3018
// missing: import/* plugins

prettierConfig,
];
48 changes: 0 additions & 48 deletions maintainers.js

This file was deleted.

83 changes: 83 additions & 0 deletions maintainers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import babelParser from '@babel/eslint-parser';
import fs from 'fs';

import eslint from '@eslint/js';
import jestPlugin from 'eslint-plugin-jest';
import prettierConfig from 'eslint-config-prettier';

import globals from 'globals';

const pkg = JSON.parse(
fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
);

/** @type {import('eslint').ESLint.Plugin} */
const plugin = {
meta: {
name: pkg.name + '/maintainers',
version: pkg.version,
},
};

/** @type {import('eslint').Linter.Config} */
export default [
{
...eslint.configs.recommended,
plugins: {
jest: jestPlugin,
[plugin.meta.name]: plugin,
},
languageOptions: {
parser: babelParser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: undefined,
},
globals: {
...globals.node,
},
},

rules: {
...eslint.configs.recommended.rules,

// eslint rules
'array-callback-return': ['error', { checkForEach: true }],
'default-param-last': 'error',
eqeqeq: ['error', 'smart'],
'linebreak-style': 'off',
'no-eval': ['error', { allowIndirect: true }],
'no-extend-native': 'error',
'no-implicit-coercion': 'error',
'no-promise-executor-return': 'error',
'no-shadow': 'error',
'no-unreachable-loop': 'error',
'no-unsafe-optional-chaining': 'error',
'require-atomic-updates': 'error',
},
},

{
// enable jest rules on test files
files: ['test/**', '**/*.spec.js*', '**/*.test.js*'],
...jestPlugin.configs['flat/recommended'],
rules: {
...jestPlugin.configs['flat/recommended'].rules,
'jest/no-disabled-tests': 'off',
'jest/no-test-prefixes': 'off',
},
languageOptions: {
globals: {
// Don't make jest globals available! These should not be available
// but imported from @jest/globals.
//
// ...globals.jest,
},
},
},

// https://github.com/import-js/eslint-plugin-import/pull/3018
// missing: import/* plugins

prettierConfig,
];
Loading