Skip to content

Commit

Permalink
ember-cli 6.1, eslint 9, eslint flat config, RFC#1055 (#320)
Browse files Browse the repository at this point in the history
* ember-cli < 6.1 is too old

* Switch to ESLint 9

* fix

* afix

* fix

* ope

* Cleanup, update prettier config

* ope

* Fix lints

* Lints

* lints

* Fix assertions

* Use TypeScript 5.6

* Upgrade typescript-eslint

* Set project: true

* Override ember-cli's tsconfig.json see: ember-cli/ember-cli#10611 and ember-cli/ember-cli#10613 and ember-cli/ember-cli#10612

* Re-lock
  • Loading branch information
NullVoxPopuli authored Jan 15, 2025
1 parent 7858389 commit 8144fec
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 551 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ node_modules/

# Test artifacts
coverage/
tests/my-addon/
tests/test-app/
9 changes: 0 additions & 9 deletions files/__addonLocation__/.eslintignore

This file was deleted.

104 changes: 0 additions & 104 deletions files/__addonLocation__/.eslintrc.cjs

This file was deleted.

114 changes: 114 additions & 0 deletions files/__addonLocation__/_js_eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* Debugging:
* https://eslint.org/docs/latest/use/configure/debug
* ----------------------------------------------------
*
* Print a file's calculated configuration
*
* npx eslint --print-config path/to/file.js
*
* Inspecting the config
*
* npx eslint --inspect-config
*
*/
import babelParser from '@babel/eslint-parser';
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import ember from 'eslint-plugin-ember/recommended';
import importPlugin from 'eslint-plugin-import';
import n from 'eslint-plugin-n';
import globals from 'globals';

const esmParserOptions = {
ecmaFeatures: { modules: true },
ecmaVersion: 'latest',
};

export default [
js.configs.recommended,
prettier,
ember.configs.base,
ember.configs.gjs,
/**
* Ignores must be in their own object
* https://eslint.org/docs/latest/use/configure/ignore
*/
{
ignores: ['dist/', 'declarations/', 'node_modules/', 'coverage/', '!**/.*'],
},
/**
* https://eslint.org/docs/latest/use/configure/configuration-files#configuring-linter-options
*/
{
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
{
files: ['**/*.js'],
languageOptions: {
parser: babelParser,
},
},
{
files: ['**/*.{js,gjs}'],
languageOptions: {
parserOptions: esmParserOptions,
globals: {
...globals.browser,
},
},
},
{
files: ['src/**/*'],
plugins: {
import: importPlugin,
},
rules: {
// require relative imports use full extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],
},
},
/**
* CJS node files
*/
{
files: [
'**/*.cjs',
'.prettierrc.js',
'.stylelintrc.js',
'.template-lintrc.js',
'addon-main.cjs',
],
plugins: {
n,
},

languageOptions: {
sourceType: 'script',
ecmaVersion: 'latest',
globals: {
...globals.node,
},
},
},
/**
* ESM node files
*/
{
files: ['**/*.mjs'],
plugins: {
n,
},

languageOptions: {
sourceType: 'module',
ecmaVersion: 'latest',
parserOptions: esmParserOptions,
globals: {
...globals.node,
},
},
},
];
133 changes: 133 additions & 0 deletions files/__addonLocation__/_ts_eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* Debugging:
* https://eslint.org/docs/latest/use/configure/debug
* ----------------------------------------------------
*
* Print a file's calculated configuration
*
* npx eslint --print-config path/to/file.js
*
* Inspecting the config
*
* npx eslint --inspect-config
*
*/
import babelParser from '@babel/eslint-parser';
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import ember from 'eslint-plugin-ember/recommended';
import importPlugin from 'eslint-plugin-import';
import n from 'eslint-plugin-n';
import globals from 'globals';
import ts from 'typescript-eslint';

const parserOptions = {
esm: {
js: {
ecmaFeatures: { modules: true },
ecmaVersion: 'latest',
},
ts: {
projectService: true,
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
};

export default ts.config(
js.configs.recommended,
ember.configs.base,
ember.configs.gjs,
ember.configs.gts,
prettier,
/**
* Ignores must be in their own object
* https://eslint.org/docs/latest/use/configure/ignore
*/
{
ignores: ['dist/', 'declarations/', 'node_modules/', 'coverage/', '!**/.*'],
},
/**
* https://eslint.org/docs/latest/use/configure/configuration-files#configuring-linter-options
*/
{
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
{
files: ['**/*.js'],
languageOptions: {
parser: babelParser,
},
},
{
files: ['**/*.{js,gjs}'],
languageOptions: {
parserOptions: parserOptions.esm.js,
globals: {
...globals.browser,
},
},
},
{
files: ['**/*.{ts,gts}'],
languageOptions: {
parser: ember.parser,
parserOptions: parserOptions.esm.ts,
},
extends: [...ts.configs.recommendedTypeChecked, ember.configs.gts],
},
{
files: ['src/**/*'],
plugins: {
import: importPlugin,
},
rules: {
// require relative imports use full extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],
},
},
/**
* CJS node files
*/
{
files: [
'**/*.cjs',
'.prettierrc.js',
'.stylelintrc.js',
'.template-lintrc.js',
'addon-main.cjs',
],
plugins: {
n,
},

languageOptions: {
sourceType: 'script',
ecmaVersion: 'latest',
globals: {
...globals.node,
},
},
},
/**
* ESM node files
*/
{
files: ['**/*.mjs'],
plugins: {
n,
},

languageOptions: {
sourceType: 'module',
ecmaVersion: 'latest',
parserOptions: parserOptions.esm.js,
globals: {
...globals.node,
},
},
},
);
Loading

0 comments on commit 8144fec

Please sign in to comment.