Skip to content

Commit

Permalink
feat: support Eslint 9
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 14, 2024
1 parent 3a3f16e commit 177a558
Show file tree
Hide file tree
Showing 26 changed files with 563 additions and 438 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
4 changes: 0 additions & 4 deletions .eslintrc.json

This file was deleted.

6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"cSpell.words": [
"astrojs",
"Globified",
"globify"
],
"cSpell.words": ["astrojs", "Globified", "globify"],
"explorer.fileNesting.patterns": {
"index.js": "*.js"
}
Expand Down
2 changes: 2 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const config = require("./index.js")
module.exports = config
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
"@typescript-eslint/eslint-plugin": "7.13.0",
"@typescript-eslint/parser": "7.13.0",
"anymatch": "^3.1.3",
"eslint": "^8.57.0",
"eslint": "^9.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-astro": "^0.34.0",
"eslint-plugin-astro": "^1.2.2",
"eslint-plugin-html": "^8.1.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-json": "^4.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-only-warn": "npm:@aminya/eslint-plugin-only-warn@^1.2.2",
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-solid": "^0.14.0",
"eslint-plugin-yaml": "^0.5.0",
"eslint-plugin-yaml": "^1.0.0",
"globify-gitignore": "^1.0.3",
"make-synchronous": "^0.1.1",
"prettier": "3.3.2",
Expand All @@ -65,7 +65,7 @@
"@types/shelljs": "^0.8.15",
"eslint-config-atomic": "link:",
"execa": "^5.1.1",
"gitly": "^2.5.3",
"gitly": "^3.0.0",
"npm-check-updates": "16.14.20",
"prettier-config-atomic": "^4.0.0",
"shelljs": "^0.8.5",
Expand Down
525 changes: 252 additions & 273 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from "prettier-config-atomic"
export default config
32 changes: 20 additions & 12 deletions src/astro.cts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { Linter } from "eslint"
import type { Linter } from "eslint"
import { pluginImportAstroRulesExtra } from "./plugin-import-rules.cjs"
import astroPlugin from "eslint-plugin-astro"
import * as onlyWarnPlugin from "eslint-plugin-only-warn"
import astroParser from "astro-eslint-parser"

export const astroConfig: Linter.ConfigOverride<Linter.RulesRecord> = {
export const astroConfig: Linter.FlatConfig<Linter.RulesRecord> = {
// astro files
...astroPlugin.configs.recommended,
files: ["*.astro"],
parser: "astro-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
extraFileExtensions: [".astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: "@typescript-eslint/parser",
extraFileExtensions: [".astro"],
},
globals: {
astroHTML: "readonly",
},
},
plugins: ["astro", "only-warn"],
extends: ["plugin:astro/recommended"],
rules: {
...pluginImportAstroRulesExtra
plugins: {
astro: astroPlugin,
"only-warn": onlyWarnPlugin,
},
globals: {
astroHTML: "readonly",
rules: {
...pluginImportAstroRulesExtra,
},
}
23 changes: 18 additions & 5 deletions src/coffeescript.cts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { pluginNodeRules } from "./plugin-node-rules.cjs"
import { pluginImportRulesExtra } from "./plugin-import-rules.cjs"
import { Linter } from "eslint"
import type { Linter } from "eslint"
import * as eslintPluginCoffee from "eslint-plugin-coffee"
import * as onlyWarnPlugin from "eslint-plugin-only-warn"
import * as nodePlugin from "eslint-plugin-node"
import * as coffeeParser from "eslint-plugin-coffee/parser"
import * as optimizeRegexPlugin from "eslint-plugin-optimize-regex"

export const coffeeConfig: Linter.ConfigOverride<Linter.RulesRecord> = {
export const coffeeConfig: Linter.FlatConfig<Linter.RulesRecord> = {
// CoffeeScript files
...eslintPluginCoffee.configs!.recommended,
...optimizeRegexPlugin.configs!.all,
...eslintPluginCoffee.configs!.prettier,
files: ["**/*.coffee"],
parser: "eslint-plugin-coffee",
plugins: ["coffee", "node", "only-warn"],
extends: ["plugin:coffee/eslint-recommended", "plugin:optimize-regex/all", "plugin:coffee/prettier"],
languageOptions: {
parser: coffeeParser,
},
plugins: {
coffee: eslintPluginCoffee,
node: nodePlugin,
"only-warn": onlyWarnPlugin,
},
rules: {
...pluginNodeRules,
...pluginImportRulesExtra,
Expand Down
4 changes: 2 additions & 2 deletions src/cson.cts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Linter } from "eslint"
import type { Linter } from "eslint"
import { coffeeConfig } from "./coffeescript.cjs"

export const csonConfig: Linter.ConfigOverride<Linter.RulesRecord> = {
export const csonConfig: Linter.FlatConfig<Linter.RulesRecord> = {
...coffeeConfig,
files: ["**/*.cson"],
rules: {
Expand Down
9 changes: 6 additions & 3 deletions src/html.cts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Linter } from "eslint"
import type { Linter } from "eslint"
import * as htmlPlugin from "eslint-plugin-html"

export const htmlConfig: Linter.ConfigOverride<Linter.RulesRecord> = {
export const htmlConfig: Linter.FlatConfig<Linter.RulesRecord> = {
files: [
"**/*.erb",
"**/*.handlebars",
Expand All @@ -16,5 +17,7 @@ export const htmlConfig: Linter.ConfigOverride<Linter.RulesRecord> = {
"**/*.xhtml",
"**/*.xml",
],
plugins: ["html"],
plugins: {
html: htmlPlugin,
},
}
4 changes: 2 additions & 2 deletions src/index-react.cts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Linter } from "eslint"
import type { Linter } from "eslint"
import base from "./index.cjs"
import { tsConfig } from "./typescript.cjs"

const nonStrictConfig: Linter.Config = {
const nonStrictConfig: Linter.FlatConfig = {
...base,
plugins: ["react", ...(base.plugins ?? [])],

Check failure on line 7 in src/index-react.cts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Type 'string' has no properties in common with type 'Plugin'.

Check failure on line 7 in src/index-react.cts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Property 'plugins' does not exist on type 'FlatConfig<RulesRecord>[]'.
extends: ["plugin:react/recommended", ...(base.extends ?? [])],

Check failure on line 8 in src/index-react.cts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Property 'extends' does not exist on type 'FlatConfig<RulesRecord>[]'.
Expand Down
38 changes: 18 additions & 20 deletions src/index-solid.cts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import { Linter } from "eslint"
import type { Linter } from "eslint"
import base from "./index.cjs"
import { tsConfig } from "./typescript.cjs"

const nonStrictConfig: Linter.Config = {
const nonStrictConfig: Linter.FlatConfig[] = [
...base,
overrides: [
// JavaScript:
{
files: ["*.js", "*.jsx", "*.mjs", "*.cjs"],
plugins: ["solid", ...(base.plugins ?? [])],
extends: ["plugin:solid/recommended", ...(base.extends ?? [])],
},
// TypeScript:
{
...tsConfig,
plugins: ["solid", ...(tsConfig.plugins ?? [])],
extends: ["plugin:solid/typescript", ...(tsConfig.extends ?? [])],
rules: tsConfig.rules,
},
// The rest is the same
...(base.overrides?.slice(1) ?? []),
],
}
// JavaScript:
{
files: ["*.js", "*.jsx", "*.mjs", "*.cjs"],
plugins: ["solid", ...(base.plugins ?? [])],

Check failure on line 10 in src/index-solid.cts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Property 'plugins' does not exist on type 'FlatConfig<RulesRecord>[]'.
extends: ["plugin:solid/recommended", ...(base.extends ?? [])],

Check failure on line 11 in src/index-solid.cts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Property 'extends' does not exist on type 'FlatConfig<RulesRecord>[]'.
},
// TypeScript:
{
...tsConfig,
plugins: ["solid", ...(tsConfig.plugins ?? [])],
extends: ["plugin:solid/typescript", ...(tsConfig.extends ?? [])],

Check failure on line 17 in src/index-solid.cts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Property 'extends' does not exist on type 'FlatConfig<RulesRecord>'.
rules: tsConfig.rules,
},
// The rest is the same
...(base.overrides?.slice(1) ?? []),
]

export default nonStrictConfig
26 changes: 13 additions & 13 deletions src/index-strict-react.cts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import nonStrictConfig from "./index-react.cjs"

// remove only-warn from javascript
if (
nonStrictConfig.plugins !== undefined &&
nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn"
) {
nonStrictConfig.plugins.pop()
}
// // remove only-warn from javascript
// if (
// nonStrictConfig.plugins !== undefined &&
// nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn"
// ) {
// nonStrictConfig.plugins.pop()
// }

// remove only-warn from overrides
nonStrictConfig.overrides?.forEach((overrides) => {
if (overrides.plugins !== undefined && overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
overrides.plugins.pop()
}
})
// // remove only-warn from overrides
// nonStrictConfig.overrides?.forEach((overrides) => {
// if (overrides.plugins !== undefined && overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
// overrides.plugins.pop()
// }
// })

export default nonStrictConfig
26 changes: 13 additions & 13 deletions src/index-strict-solid.cts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import nonStrictConfig from "./index-solid.cjs"

// remove only-warn from javascript
if (
nonStrictConfig.plugins !== undefined &&
nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn"
) {
nonStrictConfig.plugins.pop()
}
// // remove only-warn from javascript
// if (
// nonStrictConfig.plugins !== undefined &&
// nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn"
// ) {
// nonStrictConfig.plugins.pop()
// }

// remove only-warn from overrides
nonStrictConfig.overrides?.forEach((overrides) => {
if (overrides.plugins !== undefined && overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
overrides.plugins.pop()
}
})
// // remove only-warn from overrides
// nonStrictConfig.overrides?.forEach((overrides) => {
// if (overrides.plugins !== undefined && overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
// overrides.plugins.pop()
// }
// })

export default nonStrictConfig
26 changes: 13 additions & 13 deletions src/index-strict.cts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import nonStrictConfig from "./index.cjs"

// remove only-warn from javascript
if (
nonStrictConfig.plugins !== undefined &&
nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn"
) {
nonStrictConfig.plugins.pop()
}
// // remove only-warn from javascript
// if (
// nonStrictConfig.plugins !== undefined &&
// nonStrictConfig.plugins[nonStrictConfig.plugins.length - 1] === "only-warn"
// ) {
// nonStrictConfig.plugins.pop()
// }

// remove only-warn from overrides
nonStrictConfig.overrides?.forEach((overrides) => {
if (overrides.plugins !== undefined && overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
overrides.plugins.pop()
}
})
// // remove only-warn from overrides
// nonStrictConfig.overrides?.forEach((overrides) => {
// if (overrides.plugins !== undefined && overrides.plugins[overrides.plugins.length - 1] === "only-warn") {
// overrides.plugins.pop()
// }
// })

export default nonStrictConfig
43 changes: 22 additions & 21 deletions src/index.cts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { jsConfig } from "./javascript.cjs"
import { tsConfig } from "./typescript.cjs"
import { coffeeConfig } from "./coffeescript.cjs"
import { jsonConfig } from "./json.cjs"
import { csonConfig } from "./cson.cjs"
import { yamlConfig } from "./yaml.cjs"
import { htmlConfig } from "./html.cjs"
import { pluginImportSettings } from "./plugin-import-rules.cjs"
// import { pluginImportSettings } from "./plugin-import-rules.cjs"
import semverMajor from "semver/functions/major"
import { getEslintVersion } from "./eslint-version.cjs"
import { astroConfig } from "./astro.cjs"
Expand All @@ -17,6 +15,9 @@ function maybeAddCoffeeScript() {
// check if the eslint version is < 8
// and if coffee installed
if (eslintVersion < 8 && require.resolve("eslint-plugin-coffee")) {
const coffeeConfig = require("./coffee.cjs").coffeeConfig
const csonConfig = require("./cson.cjs").csonConfig

// if so try adding the coffee plugin
return [coffeeConfig, csonConfig]
}
Expand All @@ -26,23 +27,23 @@ function maybeAddCoffeeScript() {
return []
}

const config: Linter.Config = {
root: true,
env: {
atomtest: true,
es6: true,
node: true,
browser: true,
},
globals: {
atom: "readonly",
},
ignorePatterns: ["node_modules/"],
...jsConfig,
overrides: [tsConfig, jsonConfig, yamlConfig, htmlConfig, astroConfig, ...maybeAddCoffeeScript()],
settings: {
...pluginImportSettings,
},
}
const config: Linter.FlatConfig[] = [
// {
// ignores: ["node_modules/"],
// ...jsConfig,
// settings: {
// ...pluginImportSettings,
// },
// },
jsConfig,
tsConfig,
jsonConfig,
yamlConfig,
htmlConfig,
astroConfig,
...maybeAddCoffeeScript(),
]

// console.log(config)

export default config
Loading

0 comments on commit 177a558

Please sign in to comment.