Skip to content

Commit

Permalink
converting base files
Browse files Browse the repository at this point in the history
  • Loading branch information
bsokol-wl committed May 1, 2024
1 parent 4121b3a commit 7a3dca1
Show file tree
Hide file tree
Showing 16 changed files with 661 additions and 484 deletions.
23 changes: 23 additions & 0 deletions packages/eslint-plugin/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import core from "./dist/core.mjs";
import jest from "./dist/jest.mjs";
import jsxA11y from "./dist/jsx-a11y.mjs";

This comment has been minimized.

Copy link
@patricklafrance

patricklafrance May 6, 2024

Member

Is there a specific reason why this cannot continue to be an index.js file at the root of the lib folder?

We used this structure because it was the recommanded structure for ESLint plugin at the time. Did it changed?

This comment has been minimized.

Copy link
@bsokol-wl

bsokol-wl May 6, 2024

Author Contributor

This was like this in this commit because I was testing them one at a time as I converted them. In the current version, it looks like:

import workleapPlugin from "./dist/index.js";

const config = [
    {
        ignores: ["dist/"]
    },
    ...workleapPlugin.configs.typescriptLibrary
];

export default config;

But that import will get replaced by @workleap/eslint-plugin eventually

import mdx from "./dist/mdx.mjs";
import react from "./dist/react.mjs";
import storybook from "./dist/storybook.mjs";
import testingLibrary from "./dist/testing-library.mjs";
import yml from "./dist/yaml.mjs";

const config = [
...core,
jsxA11y,
mdx,
jest,
...storybook,
...react,
yml,
...testingLibrary
];

// console.log(config);

export default config;
290 changes: 144 additions & 146 deletions packages/eslint-plugin/lib/config/core.ts
Original file line number Diff line number Diff line change
@@ -1,158 +1,156 @@
import js from "@eslint/js";
import type { Linter } from "eslint";
import importPlugin from "eslint-plugin-import";
import { sourceFiles } from "../utils/patterns";

const config: Linter.Config = {
overrides: [
{
files: sourceFiles,
plugins: ["import"],
extends: [
"eslint:recommended"
],
parserOptions: {

This comment has been minimized.

Copy link
@patricklafrance

patricklafrance May 6, 2024

Member

What with are these replaced?

This comment has been minimized.

Copy link
@bsokol-wl

bsokol-wl May 6, 2024

Author Contributor

These are the default values now, so they don't need to be explicitly stated

sourceType: "module",
ecmaVersion: "latest"
},
env: {

This comment has been minimized.

Copy link
@patricklafrance

patricklafrance May 6, 2024

Member

What with are these replaced?

This comment has been minimized.

Copy link
@bsokol-wl

bsokol-wl May 6, 2024

Author Contributor

env doesn't exist anymore. You can use the Globals packege to add these in as needed. I've done this in a few places but I still need to fix the Jest environment

es2024: true,
node: true,
commonjs: true
},
rules: {
// eslint:recommended overwrite some rules
"no-cond-assign": ["error", "except-parens"],
"no-labels": ["warn", { allowLoop: true, allowSwitch: false }],
"no-prototype-builtins": "off",
const config: Linter.FlatConfig[] = [
{
files: sourceFiles,
rules: {
...js.configs.recommended.rules,
// eslint:recommended overwrite some rules
"no-cond-assign": ["error", "except-parens"],
"no-labels": ["warn", { allowLoop: true, allowSwitch: false }],
"no-prototype-builtins": "off",

// https://eslint.org/docs/rules
// Extra eslint rules
// https://eslint.org/docs/rules
// Extra eslint rules

// Possible Problems
"array-callback-return": "error",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"no-use-before-define": [
"error",
{
functions: false,
classes: false,
variables: false
}
],
// Possible Problems
"array-callback-return": "error",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"no-use-before-define": [
"error",
{
functions: false,
classes: false,
variables: false
}
],

// Suggestions
"no-array-constructor": "warn",
"no-caller": "warn",
"no-eval": "warn",
"no-extend-native": "warn",
"no-extra-bind": "warn",
"no-extra-label": "warn",
"no-implied-eval": "warn",
"no-iterator": "warn",
"no-label-var": "warn",
"no-lone-blocks": "warn",
"no-loop-func": "warn",
"no-multi-str": "warn",
"no-new-func": "warn",
"no-new-object": "warn",
"no-new-wrappers": "warn",
"no-octal-escape": "warn",
"no-useless-computed-key": "warn",
"no-useless-concat": "warn",
"no-useless-constructor": "warn",
"no-script-url": "warn",
"no-sequences": "warn",
"no-throw-literal": "warn",
"prefer-const": "warn",
"no-var": "warn",
"curly": "warn",
"no-shadow": "warn",
"no-restricted-properties": "warn",
"no-unneeded-ternary": "warn",
"no-param-reassign": "warn",
"eqeqeq": ["warn", "smart"],
"no-mixed-operators": [
"warn",
{
groups: [
["&", "|", "^", "~", "<<", ">>", ">>>"],
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
["&&", "||"],
["in", "instanceof"]
],
allowSamePrecedence: false
}
],
"no-restricted-syntax": ["error", "WithStatement"],
"no-restricted-globals": ["error"],
"no-useless-rename": [
"warn",
{
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false
}
],
"strict": ["warn", "never"],
"no-unused-expressions": [
"error",
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true
}
],
// Suggestions
"no-array-constructor": "warn",
"no-caller": "warn",
"no-eval": "warn",
"no-extend-native": "warn",
"no-extra-bind": "warn",
"no-extra-label": "warn",
"no-implied-eval": "warn",
"no-iterator": "warn",
"no-label-var": "warn",
"no-lone-blocks": "warn",
"no-loop-func": "warn",
"no-multi-str": "warn",
"no-new-func": "warn",
"no-new-object": "warn",
"no-new-wrappers": "warn",
"no-octal-escape": "warn",
"no-useless-computed-key": "warn",
"no-useless-concat": "warn",
"no-useless-constructor": "warn",
"no-script-url": "warn",
"no-sequences": "warn",
"no-throw-literal": "warn",
"prefer-const": "warn",
"no-var": "warn",
"curly": "warn",
"no-shadow": "warn",
"no-restricted-properties": "warn",
"no-unneeded-ternary": "warn",
"no-param-reassign": "warn",
"eqeqeq": ["warn", "smart"],
"no-mixed-operators": [
"warn",
{
groups: [
["&", "|", "^", "~", "<<", ">>", ">>>"],
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
["&&", "||"],
["in", "instanceof"]
],
allowSamePrecedence: false
}
],
"no-restricted-syntax": ["error", "WithStatement"],
"no-restricted-globals": ["error"],
"no-useless-rename": [
"warn",
{
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false
}
],
"strict": ["warn", "never"],
"no-unused-expressions": [
"error",
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true
}
],

// Layout & Formatting
"no-native-reassign": "warn", // deprecated replaced by no-global-assign, deja ds recommended
"no-negated-in-lhs": "warn", // deprecated replaced by no-unsafe-negation, deja ds recommended
"padding-line-between-statements": [
"warn",
{ blankLine: "always", prev: "*", next: "return" }
],
// Layout & Formatting
"no-native-reassign": "warn", // deprecated replaced by no-global-assign, deja ds recommended
"no-negated-in-lhs": "warn", // deprecated replaced by no-unsafe-negation, deja ds recommended
"padding-line-between-statements": [
"warn",
{ blankLine: "always", prev: "*", next: "return" }
],

"rest-spread-spacing": ["warn", "never"],
"unicode-bom": ["warn", "never"],
"comma-spacing": ["warn", { "before": false, "after": true }],
"keyword-spacing": ["warn", { before: true, after: true }],
"arrow-spacing": ["warn", { before: true, after: true }],
"space-before-blocks": ["warn", "always"],
"space-in-parens": ["warn", "never"],
"padded-blocks": ["warn", "never"],
"brace-style":["warn", "1tbs", { "allowSingleLine": true }],
"new-parens": "warn",
"no-whitespace-before-property": "warn",
"no-multi-spaces": "warn",
"no-multiple-empty-lines": "warn",
"space-infix-ops": "warn",
"max-len": ["warn", { tabWidth: 4, code: 300 }],
"indent": [
"warn",
4,
{
SwitchCase: 1,
CallExpression: { arguments: "first" }
}
],
"semi": ["warn", "always"],
"quotes": ["warn", "double"],
"comma-dangle": ["warn", "never"],
"object-curly-spacing": ["warn", "always"],
"dot-location": ["warn", "property"],
"arrow-parens": ["warn", "as-needed"],
"rest-spread-spacing": ["warn", "never"],
"unicode-bom": ["warn", "never"],
"comma-spacing": ["warn", { "before": false, "after": true }],
"keyword-spacing": ["warn", { before: true, after: true }],
"arrow-spacing": ["warn", { before: true, after: true }],
"space-before-blocks": ["warn", "always"],
"space-in-parens": ["warn", "never"],
"padded-blocks": ["warn", "never"],
"brace-style":["warn", "1tbs", { "allowSingleLine": true }],
"new-parens": "warn",
"no-whitespace-before-property": "warn",
"no-multi-spaces": "warn",
"no-multiple-empty-lines": "warn",
"space-infix-ops": "warn",
"max-len": ["warn", { tabWidth: 4, code: 300 }],
"indent": [
"warn",
4,
{
SwitchCase: 1,
CallExpression: { arguments: "first" }
}
],
"semi": ["warn", "always"],
"quotes": ["warn", "double"],
"comma-dangle": ["warn", "never"],
"object-curly-spacing": ["warn", "always"],
"dot-location": ["warn", "property"],
"arrow-parens": ["warn", "as-needed"]

// https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules
"import/no-amd": "error",
"import/no-webpack-loader-syntax": "error",
"import/no-self-import": "error",
"import/newline-after-import" : "warn",
"import/no-duplicates": "warn"
}
},
{
files: sourceFiles,
plugins: { import: importPlugin },
// These settings should be temporary until the import plugin is updated
// https://github.com/import-js/eslint-plugin-import/issues/2556
settings: {
"import/parsers": {
espree: [".js", ".cjs", ".mjs", ".jsx"]
}
},
rules: {
// https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules
"import/no-amd": "error",
"import/no-webpack-loader-syntax": "error",
"import/no-self-import": "error",
"import/newline-after-import" : "warn",
"import/no-duplicates": "warn"
}
]
};
}
];

// Using TypeScript "export" keyword until ESLint support ESM.
// Otherwise we must deal with a weird CommonJS output from esbuild which is not worth it.
// For more info, see: https://github.com/evanw/esbuild/issues/1079
export = config;
export default config;

This comment has been minimized.

Copy link
@patricklafrance

patricklafrance May 6, 2024

Member

Are the recommending to with default exports or named exports?

This comment has been minimized.

Copy link
@bsokol-wl

bsokol-wl May 6, 2024

Author Contributor

They recommend default export, but since it's all JavaScript now, ESLint doesn't need you to adhere to any specific convention anymore.

38 changes: 12 additions & 26 deletions packages/eslint-plugin/lib/config/jest.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import jestPlugin from 'eslint-plugin-jest';
import { reactTestFiles, testFiles } from "../utils/patterns";

import type { Linter } from "eslint";

const config: Linter.Config = {
overrides: [
{
files: [...testFiles, ...reactTestFiles],
plugins: ["jest"],
env: {
es2024: true,
node: true,
browser: true,
commonjs: true,
jest: true
},
extends: ["plugin:jest/recommended"],
rules: {
// Prefer spies to allow for automatic restoration
"jest/prefer-spy-on": "error",
// Gives better failure messages for array checks
"jest/prefer-to-contain": "error"
}
}
]
};
const config: Linter.FlatConfig = {
files: [...testFiles, ...reactTestFiles],
...jestPlugin.configs['flat/recommended'],

This comment has been minimized.

Copy link
@patricklafrance

patricklafrance May 6, 2024

Member

We usually used double quotes instead of single quotes

This comment has been minimized.

Copy link
@bsokol-wl

bsokol-wl May 6, 2024

Author Contributor

ESLint fixed it for me in a later commit

rules: {
// Prefer spies to allow for automatic restoration
"jest/prefer-spy-on": "error",
// Gives better failure messages for array checks
"jest/prefer-to-contain": "error"
}
}

// Using TypeScript "export" keyword until ESLint support ESM.
// Otherwise we must deal with a weird CommonJS output from esbuild which is not worth it.
// For more info, see: https://github.com/evanw/esbuild/issues/1079
export = config;
export default config;
Loading

0 comments on commit 7a3dca1

Please sign in to comment.