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

ci: use eslint flat config #400

Merged
merged 8 commits into from
Jan 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
121 changes: 0 additions & 121 deletions .eslintrc.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/postCommit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ jobs:
- name: Check environment
run: 'npx eslint --env-info && echo ---- && echo "stylelint: "$(npx stylelint --version) && echo ---- && echo "v8r: "$(npx v8r --version) && echo ---- && mkdir -vp .cache && echo ".cache:" && ls -lhA .cache'
- name: Run eslint
run: npx eslint --cache --cache-strategy content --cache-location ".cache/" --ext js --exit-on-fatal-error --format @annangela/eslint-formatter-gha --max-warnings 0 ./src
run: npx eslint --cache --cache-strategy content --cache-location ".cache/" --exit-on-fatal-error --format @annangela/eslint-formatter-gha --max-warnings 0 ./src
- name: Run stylelint
run: npx stylelint --cache --cache-strategy content --cache-location ".cache/" --formatter github --max-warnings 0 "src/**/*.css"
- name: Run v8r
run: echo "::group::v8r output" && npx v8r && echo "::endgroup::"
run: npx v8r
- name: Check .mailmap
if: needs.postCommit.result == 'success'
run: node scripts/emailmapChecker/index.js
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"./.vscode/json-schemas/gadget-definition.json": "src/gadgets/*/definition.yaml"
},
"files.insertFinalNewline": true,
"eslint.experimental.useFlatConfig": false,
"eslint.experimental.useFlatConfig": true,
"conventionalCommits.scopes": [
"Gadget-abusefilter33test",
"Gadget-abusefilterEdit",
Expand Down Expand Up @@ -126,7 +126,6 @@
"Gadget-widgetPreload",
"Gadget-wikiBlame",
"Gadget-wikieditor-highlight",
"Gadget-wikieditor-highlight-cm6",
"Gadget-Wikiplus",
"Gadget-wikiplus-highlight",
"Gadget-zeroFill",
Expand Down
141 changes: 141 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import fs from "node:fs";
import path from "node:path";
import YAML from "yaml";
import { configs } from "@annangela/eslint-config";
import readDir from "./scripts/modules/readDir.js";

/**
* @type { import("eslint").Linter.FlatConfigFileSpec }
*/
const ignores = [
"**/dist/**",
"**/.*/**",
"node_modules",
];

const srcESlintrcFiles = (await readDir("./src")).filter((n) => path.basename(n) === ".eslintrc.yaml");
for (const srcESlintrcFile of srcESlintrcFiles) {
const dir = path.dirname(srcESlintrcFile);
const srcESlintrc = YAML.parse(await fs.promises.readFile(srcESlintrcFile, { encoding: "utf-8" }));
if (Array.isArray(srcESlintrc.ignorePatterns)) {
for (const ignorePattern of srcESlintrc.ignorePatterns) {
ignores.push(path.join(dir, ignorePattern));
}
}
}

/**
* @typedef { Pick<import("eslint").Linter.FlatConfig, "files" | "ignores"> } FileSpec
*/
/**
* @type { { browser: FileSpec, node: FileSpec } }
*/
const fileSpec = {
browser: {
files: [
"src/**/*",
"scripts/generatePolyfill/template.js",
],
ignores,
},
node: {
files: [
"scripts/**/*",
"eslint.config.js",
],
ignores: [
...ignores,
"scripts/generatePolyfill/template.js",
],
},
};

/**
* @type { import("eslint").Linter.FlatConfig[] }
*/
const config = [
// base
{
...configs.base,
ignores,
},
{
...configs.browser,
...fileSpec.browser,
},
{
...fileSpec.browser,
languageOptions: {
globals: {
mw: false,
mediaWiki: false,
OO: false,
localforage: false,
moment: false,
LocalObjectStorage: false,
insertToBottomRightCorner: false,
wgULS: false,
wgUVS: false,
hashwasm: false,
oouiDialog: false,
echarts: false,
MOE_SKIN_GLOBAL_DATA_REF: false,
ace: false,
libCachedCode: false,
CodeMirror: false,
},
},
},
{
...configs.node,
...fileSpec.node,
},
{
ignores,
rules: {
// other disabled rules for all files
"@stylistic/no-mixed-operators": "off",
},
},
{
...fileSpec.browser,
rules: {
// other disabled rules for browser files
"promise/prefer-await-to-callbacks": "off",
},
},
{
...fileSpec.node,
rules: {
// Running in trusted environment
"security/detect-unsafe-regex": "off",
"security/detect-object-injection": "off",
"security/detect-non-literal-fs-filename": "off",
"security/detect-non-literal-regexp": "off",
"security/detect-child-process": "off",
"n/no-extraneous-import": "off",
"n/no-process-exit": "off",

// github api use underscores naming
camelcase: [
"error",
{
allow: [
"pull_number",
"issue_number",
"head_commit",
"commit_long",
"state_reason",
"workflow_id",
"exclude_pull_requests",
"per_page",
"workflow_runs",
],
},
],

// other disabled rules for node files
},
},
];
export default config;
Loading