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

[DEV-18547] Feature - Support ESLint v9 #13

Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a070824
Flatten configurations to support ESLint v9
mohammadxali Nov 19, 2024
d2ed03f
Migrate to Pnpm
mohammadxali Nov 19, 2024
b1e5b59
Install a few dev dependencies
mohammadxali Nov 19, 2024
88d0001
Setup a TSConfig file in the project's root
mohammadxali Nov 19, 2024
0df2dae
Setup test script
mohammadxali Nov 19, 2024
c38cdee
Upgrade all packages to their latest version
mohammadxali Nov 19, 2024
c25330b
Revert `test` script
mohammadxali Nov 19, 2024
457b540
5.4.6-0
mohammadxali Nov 19, 2024
acf173e
Pass env via `languageOptions.globals`
mohammadxali Nov 19, 2024
337ac60
Upgrade `peerDependency` eslint version to v9
mohammadxali Nov 19, 2024
e50f5c5
5.4.6-1
mohammadxali Nov 19, 2024
f1a6669
Convert all `require()` syntax to `import`
mohammadxali Nov 19, 2024
6cc4d0b
Add `type: "module"` to root `package.json` file
mohammadxali Nov 19, 2024
82e284f
5.4.6-2
mohammadxali Nov 19, 2024
6504369
Use default export for all rule-config utils
mohammadxali Nov 19, 2024
b34d13c
5.4.6-3
mohammadxali Nov 19, 2024
25dd087
Add `export default` to rest of eslint configs
mohammadxali Nov 19, 2024
d425192
5.4.6-4
mohammadxali Nov 19, 2024
24bd409
Use `import()` syntax for plugins as well
mohammadxali Nov 19, 2024
bef597d
5.4.6-5
mohammadxali Nov 19, 2024
2c47c67
Move `ecmaFeatures` to `parserOptions` for v9
mohammadxali Nov 19, 2024
d4bd1f6
5.4.6-6
mohammadxali Nov 19, 2024
519593c
Install v9 compatible eslint packages
mohammadxali Nov 19, 2024
7c869f9
Rework the configuration files to support the new config
mohammadxali Nov 19, 2024
0164fef
Setup a playground testing project to test config
mohammadxali Nov 19, 2024
bbf6589
5.4.6-7
mohammadxali Nov 19, 2024
bd2d71e
Fix react-hooks plugin throwing
mohammadxali Nov 19, 2024
a661a2d
5.4.6-8
mohammadxali Nov 19, 2024
cf33661
Install types for `eslint-config-prettier` package
mohammadxali Nov 19, 2024
4cb2a2d
Make prettier and styling files esm compatible
mohammadxali Nov 19, 2024
c7abe93
Include `eslintConfigPrettier` in v9 compatible way
mohammadxali Nov 19, 2024
3fb6ce9
5.4.6-9
mohammadxali Nov 19, 2024
d98f9bf
Fix the path in exports field
mohammadxali Nov 19, 2024
eaae9d9
5.4.6-10
mohammadxali Nov 19, 2024
23657ee
Add a smoke test to verify package working
mohammadxali Nov 19, 2024
000a801
Make test example apps as part of pnpm workspace
mohammadxali Nov 19, 2024
9a495bb
Deduplicate packages so that root ones are used
mohammadxali Nov 19, 2024
65cd05b
Set node and pnpm versions
mohammadxali Nov 19, 2024
af6f42c
Try treating lint failure as a success to test
mohammadxali Nov 19, 2024
bba9d59
Try `continue-on-error` option
mohammadxali Nov 19, 2024
de8f1c5
Evaluate ESLint result in a next step
mohammadxali Nov 19, 2024
6a5d291
Make eslint test pass
mohammadxali Nov 19, 2024
fbaba2a
Introduce a `should-fail` and a `should-pass` test case
mohammadxali Nov 19, 2024
e628986
Check for the var existence
mohammadxali Nov 19, 2024
63c7666
Rename `lint` to `test` in GH Action
mohammadxali Nov 19, 2024
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
70 changes: 70 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Smoke Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Setup environment
uses: prezly/setup-github-actions@v1
with:
pnpm: 9.7.0
node: 20

- name: Install dependencies
run: pnpm install

- name: Run ESLint on should-fail
id: eslint_should_fail
run: |
cd tests/should-fail
pnpm lint
lint_exit_code=$?
echo "The exit code of pnpm lint for should-fail is: $lint_exit_code"
echo "lint_exit_code=$lint_exit_code" >> $GITHUB_ENV
continue-on-error: true

- name: Evaluate ESLint result for should-fail
run: |
if [ -n "$lint_exit_code" ]; then
echo "ESLint for should-fail passed unexpectedly. Marking this as a failure."
exit 1
else
echo "ESLint for should-fail failed as expected. Marking this as a success."
exit 0
fi
env:
lint_exit_code: ${{ env.lint_exit_code }}

- name: Run ESLint on should-pass
id: eslint_should_pass
run: |
cd tests/should-pass
pnpm lint
lint_exit_code=$?
echo "The exit code of pnpm lint for should-pass is: $lint_exit_code"
echo "lint_exit_code=$lint_exit_code" >> $GITHUB_ENV
continue-on-error: true

- name: Evaluate ESLint result for should-pass
run: |
if [ "$lint_exit_code" -eq 0 ]; then
echo "ESLint for should-pass passed as expected. Marking this as a success."
exit 0
else
echo "ESLint for should-pass failed unexpectedly. Marking this as a failure."
exit 1
fi
env:
lint_exit_code: ${{ env.lint_exit_code }}
202 changes: 119 additions & 83 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,130 @@
const importOrderConfig = require("./rule-configs/import-order/base.js");
const namingConventionConfig = require("./rule-configs/naming-convention/base.js");
//@ts-check
import importOrderConfig from "./rule-configs/import-order/base.js";
import namingConventionConfig from "./rule-configs/naming-convention/base.js";
import typescriptEslintPlugin from "@typescript-eslint/eslint-plugin";
import prettierPlugin from "eslint-plugin-prettier";
import sortExportAllPlugin from "eslint-plugin-sort-export-all";
import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier";

module.exports = {
env: {
browser: true,
es2021: true,
node: true,
//@ts-ignore -- Package provides no types.
import reactRefresh from "eslint-plugin-react-refresh";
//@ts-ignore -- Package provides no types.
import importPlugin from "eslint-plugin-import";

export default tseslint.config(
{
ignores: ["dist"],
},
extends: ["airbnb-base", "airbnb-typescript/base", "prettier"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ["**/*.{ts,tsx,js,jsx,mjs}"],
languageOptions: {
ecmaVersion: 2020,
parserOptions: {
projectService: true,
},
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
"react-refresh": reactRefresh,
},
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
ecmaVersion: 12,
sourceType: "module",
project: ["./tsconfig.json"],
},
plugins: [
"@typescript-eslint",
"prettier",
"import",
"sort-export-all",
"deprecation",
],
rules: {
// Prettier handles indent, whitespace and empty lines
"prettier/prettier": 2,
{
plugins: {
"@typescript-eslint": typescriptEslintPlugin,
prettier: prettierPlugin,
import: importPlugin,
"sort-export-all": sortExportAllPlugin,
},
rules: {
// Prettier rules
"prettier/prettier": 2,

// Warn about deprecated methods and properties
"deprecation/deprecation": "warn",
// Warn about deprecated methods and properties
"@typescript-eslint/no-deprecated": "warn",

// Import rules
"sort-export-all/sort-export-all": [
"error",
"asc",
{
caseSensitive: false,
natural: false,
},
],
"import/extensions": [
"error",
"never",
{ svg: "always", json: "always", css: "always", scss: "always" },
],
"import/order": ["error", importOrderConfig],
"import/prefer-default-export": "off",
"import/no-default-export": "error",
"import/no-extraneous-dependencies": "error",
"sort-imports": [
"error",
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
},
],
// Import rules
"sort-export-all/sort-export-all": [
"error",
"asc",
{
caseSensitive: false,
natural: false,
},
],
"import/extensions": [
"error",
"never",
{
svg: "always",
json: "always",
css: "always",
scss: "always",
},
],
"import/order": ["error", importOrderConfig],
"import/prefer-default-export": "off",
"import/no-default-export": "error",
"import/no-extraneous-dependencies": "error",
"sort-imports": [
"error",
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: [
"none",
"all",
"multiple",
"single",
],
},
],

// General code-style rules
"@typescript-eslint/naming-convention": namingConventionConfig,
"id-blacklist": [
2,
"arr",
"cb",
"e",
"el",
"err",
"idx",
"num",
"str",
"tmp",
"val",
],
"no-return-assign": ["error", "except-parens"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", ignoreRestSiblings: true },
],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-import-type-side-effects": "error",
// General code-style rules
// @ts-ignore
"@typescript-eslint/naming-convention": namingConventionConfig,
"id-blacklist": [
2,
"arr",
"cb",
"e",
"el",
"err",
"idx",
"num",
"str",
"tmp",
"val",
],
"no-return-assign": ["error", "except-parens"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", ignoreRestSiblings: true },
],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-import-type-side-effects": "error",

"prefer-destructuring": "warn",
"no-nested-ternary": "warn",
"prefer-destructuring": "warn",
"no-nested-ternary": "warn",

"func-style": ["error", "declaration"],
"func-style": ["error", "declaration"],

// Extra rules
radix: "off",
radix: "off",
},
},
};
eslintConfigPrettier,
);
18 changes: 10 additions & 8 deletions lib/nextjs-tailwind.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const importOrderConfig = require("./rule-configs/import-order/next.js");
const namingConventionConfig = require("./rule-configs/naming-convention/next-tailwind.js");
import namingConventionConfig from "./rule-configs/naming-convention/next-tailwind.js";
import nextJsConfig from "./nextjs.js";

module.exports = {
extends: [require.resolve("./nextjs.js")],
rules: {
// General code-style rules
"@typescript-eslint/naming-convention": namingConventionConfig,
export default [
...nextJsConfig,
{
files: ["**/*.{ts,tsx,js,jsx}"],
rules: {
"@typescript-eslint/naming-convention": namingConventionConfig,
},
},
};
];
Loading
Loading