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

chore: use flat config & eslint v9 #152

Merged
merged 8 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

71 changes: 0 additions & 71 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/GHPages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Install Packages
run: npm i
run: npm i -f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: you can add force=true to the .npmrc, to avoid repeating. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I didn't know that. That's useful.

- name: Build docs
run: |+
npm run docs:build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/NpmPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
registry-url: "https://registry.npmjs.org"
- name: Install Packages
run: npm i
run: npm i -f
- name: test
run: npm run test:mocha
- name: check can npm-publish
Expand Down
27 changes: 13 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
- name: Install Packages
run: npm install
run: npm install -f
- name: Lint
run: npm run -s lint

Expand All @@ -27,24 +27,23 @@ jobs:
strategy:
matrix:
include:
- eslint: 8
node: 18
- eslint: 9
node: 20
os: ubuntu-latest
# On other platforms
- eslint: 8
node: 18
- eslint: 9
node: 20
os: windows-latest
- eslint: 8
node: 18
os: macos-latest
# On next Node.js versions
- eslint: ^9.0.0-0
- eslint: 9
node: 20
os: ubuntu-latest
os: macos-latest
# On other Node.js versions
- eslint: 8
node: 19
os: ubuntu-latest
- eslint: 9
node: 18
os: ubuntu-latest
- eslint: 8
node: 16
os: ubuntu-latest
Expand Down Expand Up @@ -76,14 +75,14 @@ jobs:
node-version: ${{ matrix.node }}
- name: Uninstall Packages
run: |+
npm r -D vuepress eslint-plugin-eslint-plugin eslint-plugin-prettier vue-eslint-parser eslint-plugin-vue
npm r -D vuepress eslint-plugin-eslint-plugin eslint-plugin-prettier vue-eslint-parser eslint-plugin-vue -f
- name: Install ESLint ${{ matrix.eslint }}
run: |+
npm install -D eslint@${{ matrix.eslint }} --legacy-peer-deps
npm install -D eslint@${{ matrix.eslint }} -f
npx rimraf node_modules
- name: Install "@typescript-eslint/parser" ${{ matrix.tseslint }}
run: |+
npm install -D @typescript-eslint/parser@${{ matrix.tseslint }}
npm install -D @typescript-eslint/parser@${{ matrix.tseslint }} -f
npx rimraf node_modules
if: matrix.tseslint == 5
- name: Install Packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
node-version: 18
- name: Install Packages
run: npm install
run: npm install -f
- name: Update
run: npm run resource-update:unicode-properties
- uses: peter-evans/create-pull-request@v6
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
"javascript",
"vue"
],
"eslint.options": {
"rulePaths": ["eslint-internal/rules"]
},
}
26 changes: 0 additions & 26 deletions docs/.vitepress/.eslintrc.js

This file was deleted.

37 changes: 35 additions & 2 deletions docs/.vitepress/theme/components/eslint-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,43 @@ function lint() {
}
}
function getRuleDocUrl(ruleId) {
if (!ruleId.includes("/")) {
return `https://eslint.org/docs/rules/${ruleId}`
}
for (const config of [props.config].flat()) {
if (
config &&
config.plugins &&
typeof config.plugins === "object" &&
!Array.isArray(config.plugins)
) {
for (const [pluginId, plugin] of Object.entries(config.plugins)) {
const pluginName = pluginId
.replace(/^eslint-plugin-/u, "")
.replace(/\/eslint-plugin$/u, "")
.replace(/\/eslint-plugin-/u, "/")
if (!ruleId.startsWith(`${pluginName}/`)) {
continue
}
const pluginRuleName = ruleId.slice(pluginName.length + 1)
const rule = plugin.rules?.[pluginRuleName]
if (
rule &&
typeof rule !== "function" &&
rule?.meta?.docs?.url
) {
return rule.meta.docs.url
}
}
}
}
return null
}
/** Linter message to monaco editor marker */
function messageToMarker(message) {
const rule = message.ruleId && linter.value?.getRules().get(message.ruleId)
const docUrl = rule && rule.meta && rule.meta.docs && rule.meta.docs.url
const docUrl = message.ruleId && getRuleDocUrl(message.ruleId)
const startLineNumber = ensurePositiveInt(message.line, 1)
const startColumn = ensurePositiveInt(message.column, 1)
const endLineNumber = ensurePositiveInt(message.endLine, startLineNumber)
Expand Down
91 changes: 47 additions & 44 deletions docs/.vitepress/theme/components/eslint-playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,57 @@ const format = reactive({
})

const config = computed(() => ({
globals: {
// ES2015 globals
ArrayBuffer: false,
DataView: false,
Float32Array: false,
Float64Array: false,
Int16Array: false,
Int32Array: false,
Int8Array: false,
Map: false,
Promise: false,
Proxy: false,
Reflect: false,
Set: false,
Symbol: false,
Uint16Array: false,
Uint32Array: false,
Uint8Array: false,
Uint8ClampedArray: false,
WeakMap: false,
WeakSet: false,
// ES2017 globals
Atomics: false,
SharedArrayBuffer: false,
// ES2020 globals
BigInt: false,
BigInt64Array: false,
BigUint64Array: false,
globalThis: true,
// ES2021 globals
AggregateError: false,
FinalizationRegistry: false,
WeakRef: false,
// Intl
Intl: false,
plugins: {
"es-x": {
rules,
},
},
rules: {},
parserOptions: {
ecmaVersion: "latest",
languageOptions: {
sourceType: props.sourceType,
ecmaFeatures: {
jsx: true,
ecmaVersion: "latest",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
// ES2015 globals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to specify es globals - in flat mode, they should have been enabled by default.

ArrayBuffer: false,
DataView: false,
Float32Array: false,
Float64Array: false,
Int16Array: false,
Int32Array: false,
Int8Array: false,
Map: false,
Promise: false,
Proxy: false,
Reflect: false,
Set: false,
Symbol: false,
Uint16Array: false,
Uint32Array: false,
Uint8Array: false,
Uint8ClampedArray: false,
WeakMap: false,
WeakSet: false,
// ES2017 globals
Atomics: false,
SharedArrayBuffer: false,
// ES2020 globals
BigInt: false,
BigInt64Array: false,
BigUint64Array: false,
globalThis: true,
// ES2021 globals
AggregateError: false,
FinalizationRegistry: false,
WeakRef: false,
// Intl
Intl: false,
},
},
rules: {},
settings: {
"es-x": { aggressive: true },
},
Expand All @@ -109,10 +116,6 @@ onMounted(async () => {
const [{ Linter }] = await Promise.all([import("eslint")])

linter.value = markRaw(new Linter())

for (const ruleId of Object.keys(rules)) {
linter.value.defineRule(`es-x/${ruleId}`, rules[ruleId])
}
})

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/components/monaco-editor.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { loadMonacoEditor, setupMonacoEditor } from "./monaco/index"
import { loadMonacoEditor, setupMonacoEditor } from "./monaco/index.mjs"
import { onBeforeUnmount, onMounted, ref, watch } from "vue"
const props = defineProps({
Expand Down
11 changes: 8 additions & 3 deletions eslint-internal/config/+browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

const globals = require("./_browser-globals")

module.exports = {
globals,
}
module.exports = [
{
name: "eslint-internal/config/+browser.js",
languageOptions: {
globals,
},
},
]