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

feat(eslint-plugin): support Eslint 9 and 8 simultaneously #7072

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
33904d7
feat: let eslint-plugin-qwink support Eslint 9 and 8 simultaneously
Nov 19, 2024
93f850e
feat: let eslint-plugin-qwink support Eslint 9 and 8 simultaneously
Nov 19, 2024
83909c4
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Nov 19, 2024
6953229
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Nov 22, 2024
efb017d
support 8 and 9
Nov 22, 2024
f2bdd0d
Merge branch '6048_eslint-flag' of https://github.com/JerryWu1234/qwi…
Nov 22, 2024
5c0723e
upgrade
Nov 22, 2024
0738804
upgrade
Nov 22, 2024
5ed62c5
upgrade
Nov 22, 2024
35ccf83
upgrade
Nov 22, 2024
df6f8f9
Merge branch '6048_eslint-flag' of https://github.com/JerryWu1234/qwi…
Nov 22, 2024
fc3aa53
Update qwik-binding-map.ts
JerryWu1234 Nov 22, 2024
f6d7862
upgrade
Nov 22, 2024
af55f94
upgrade
Nov 22, 2024
64b5c11
upgrade
Nov 22, 2024
cce51f0
upgrade
Nov 22, 2024
20a6fd4
upgrade
Nov 22, 2024
0bda546
upgrade
Nov 22, 2024
02cba46
fix
Nov 22, 2024
5701e52
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Nov 27, 2024
0f75492
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Nov 28, 2024
2458862
fix
Nov 28, 2024
b82a195
Merge branch '6048_eslint-flag' of https://github.com/JerryWu1234/qwi…
Nov 28, 2024
278a5df
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Nov 29, 2024
d378168
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Dec 6, 2024
0dab706
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Dec 10, 2024
fc93083
fix
JerryWu1234 Dec 11, 2024
07427ad
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Dec 11, 2024
13efa82
fix
JerryWu1234 Dec 11, 2024
939f856
Merge branch '6048_eslint-flag' of https://github.com/JerryWu1234/qwi…
JerryWu1234 Dec 11, 2024
13421f3
fix
JerryWu1234 Dec 12, 2024
88efe1b
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Dec 13, 2024
3a5aae2
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Dec 27, 2024
1276d1e
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Dec 31, 2024
aa1d5fb
fix
Dec 31, 2024
5f4e62e
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Jan 12, 2025
142761d
Update breezy-toes-help.md
JerryWu1234 Jan 18, 2025
c16404b
fix error ts
JerryWu1234 Jan 25, 2025
692b768
fix error when using in eslint 9
JerryWu1234 Jan 25, 2025
43cff26
fix get an error when getscope no param
JerryWu1234 Jan 25, 2025
b34da96
test
JerryWu1234 Jan 25, 2025
8f1fa6c
test
JerryWu1234 Jan 25, 2025
6ab2780
fix console
JerryWu1234 Jan 25, 2025
7ea5e59
fix ts an error
JerryWu1234 Jan 25, 2025
f348826
fix ts an error
JerryWu1234 Jan 25, 2025
a4946d3
fix dependency error
JerryWu1234 Jan 25, 2025
e1993a5
fix
JerryWu1234 Jan 25, 2025
b0b17aa
fix: appear an error when @types/eslint is 9 version
JerryWu1234 Jan 26, 2025
f2aca1c
Merge branch 'main' into 6048_eslint-flag
JerryWu1234 Jan 26, 2025
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
5 changes: 5 additions & 0 deletions .changeset/breezy-toes-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-qwik': major
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
---

let eslint-plugin-qwik support Eslint 9 and 8 simultaneously
2 changes: 1 addition & 1 deletion e2e/qwik-cli-e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function replacePackagesWithLocalOnes(tmpDir: string) {
for (const { name, absolutePath } of tarballConfig) {
patchPackageJsonForPlugin(tmpDir, name, absolutePath);
}
execSync('npm i', {
execSync('pnpm i', {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

did you guys discuss it? what was the answer?

Copy link
Member

Choose a reason for hiding this comment

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

@JerryWu1234 what happens if you leave this as npm?

cwd: tmpDir,
// only output errors
stdio: ['ignore', 'ignore', 'inherit'],
Expand Down
90 changes: 62 additions & 28 deletions packages/eslint-plugin-qwik/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { preferClasslist } from './src/preferClasslist';
import { unusedServer } from './src/unusedServer';
import { useMethodUsage } from './src/useMethodUsage';
import { validLexicalScope } from './src/validLexicalScope';
import pkg from './package.json';

export const rules = {
const rules = {
'use-method-usage': useMethodUsage,
'valid-lexical-scope': validLexicalScope,
'loader-location': loaderLocation,
Expand All @@ -24,37 +25,70 @@ export const rules = {
'no-use-visible-task': noUseVisibleTask,
};

export const configs = {
const recommendedRules = {
'qwik/use-method-usage': 'error',
'qwik/valid-lexical-scope': 'error',
'qwik/no-react-props': 'error',
'qwik/prefer-classlist': 'warn',
'qwik/jsx-no-script-url': 'warn',
'qwik/loader-location': 'warn',
'qwik/jsx-key': 'warn',
'qwik/unused-server': 'error',
'qwik/jsx-img': 'warn',
'qwik/jsx-a': 'warn',
'qwik/no-use-visible-task': 'warn',
};
const strictRules = {
'qwik/valid-lexical-scope': 'error',
'qwik/use-method-usage': 'error',
'qwik/loader-location': 'error',
'qwik/no-react-props': 'error',
'qwik/prefer-classlist': 'error',
'qwik/jsx-no-script-url': 'error',
'qwik/jsx-key': 'error',
'qwik/unused-server': 'error',
'qwik/jsx-img': 'error',
'qwik/jsx-a': 'error',
'qwik/no-use-visible-task': 'warn',
};

const configs = {
recommended: {
plugins: ['qwik'],
rules: {
'qwik/use-method-usage': 'error',
'qwik/valid-lexical-scope': 'error',
'qwik/no-react-props': 'error',
'qwik/prefer-classlist': 'warn',
'qwik/jsx-no-script-url': 'warn',
'qwik/loader-location': 'warn',
'qwik/jsx-key': 'warn',
'qwik/unused-server': 'error',
'qwik/jsx-img': 'warn',
'qwik/jsx-a': 'warn',
'qwik/no-use-visible-task': 'warn',
},
rules: recommendedRules,
},
strict: {
plugins: ['qwik'],
rules: {
'qwik/valid-lexical-scope': 'error',
'qwik/use-method-usage': 'error',
'qwik/loader-location': 'error',
'qwik/no-react-props': 'error',
'qwik/prefer-classlist': 'error',
'qwik/jsx-no-script-url': 'error',
'qwik/jsx-key': 'error',
'qwik/unused-server': 'error',
'qwik/jsx-img': 'error',
'qwik/jsx-a': 'error',
'qwik/no-use-visible-task': 'warn',
},
rules: strictRules,
},
};

const qwikEslintPlugin = {
configs: {},
meta: {
name: pkg.name,
version: pkg.version,
},
rules,
};

Object.assign(qwikEslintPlugin.configs, {
recommended: [
{
plugins: {
qwik: qwikEslintPlugin,
},
rules: recommendedRules,
},
],
strict: [
{
plugins: {
qwik: qwikEslintPlugin,
},
rules: strictRules,
},
],
});

export { configs, qwikEslintPlugin as default, rules };
5 changes: 2 additions & 3 deletions packages/eslint-plugin-qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"devDependencies": {
"@builder.io/qwik": "workspace:^",
"@builder.io/qwik-city": "workspace:^",
"@types/eslint": "8.56.10",
"@types/estree": "1.0.5",
"@typescript-eslint/rule-tester": "7.8.0",
"@typescript-eslint/rule-tester": "8.14.0",
"redent": "4.0.0"
},
"engines": {
Expand All @@ -32,7 +31,7 @@
"license": "MIT",
"main": "dist/index.js",
"peerDependencies": {
"eslint": "^8.57.0"
"@types/eslint": "9.6.1"
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be a peer dependency, should it? Is it necessary for the plugin to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eslint isn’t necessary.
and @types/eslint should be a peer dependency to prevent build error

Copy link
Member

Choose a reason for hiding this comment

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

What is the build error?

Users will just install the eslint plugin, they won't use any eslint code. They will only use eslint to check the code. So I don't understand why the types need to be installed.

I think this needs to be a dev dependency?

},
"repository": {
"type": "git",
Expand Down
32 changes: 16 additions & 16 deletions packages/eslint-plugin-qwik/qwik.unit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as vitest from 'vitest';
// @ts-ignore
import { RuleTester } from '@typescript-eslint/rule-tester';

import { RuleTester, type RuleTesterConfig } from '@typescript-eslint/rule-tester';
import { fileURLToPath } from 'node:url';
import { rules } from './index';
import { readdir, readFile, stat } from 'node:fs/promises';
Expand All @@ -14,22 +12,24 @@ RuleTester.itOnly = vitest.it.only;
RuleTester.describe = vitest.describe;

const testConfig = {
parser: '@typescript-eslint/parser',
env: {
es6: true,
},
parserOptions: {
tsconfigRootDir: fileURLToPath(new URL('.', import.meta.url)),
project: ['./tests/tsconfig.json'],
ecmaFeatures: {
jsx: true,
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.ts*'],
},
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},

ecmaVersion: 2024,
project: ['./tests/tsconfig.json'],
tsconfigRootDir: fileURLToPath(new URL('.', import.meta.url)),
},
ecmaVersion: 2020,
sourceType: 'module',
},
};
} as RuleTesterConfig;

const ruleTester = new RuleTester(testConfig as any);
const ruleTester = new RuleTester(testConfig);
interface TestCase {
name: string;
filename: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const HelloWorld = component$(() => {
class Stuff {}
const stuff = new Stuff();
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
console.log(stuff);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Expect error: { "messageId": "invalidJsxDollar" }
import { component$, useTask$ } from '@builder.io/qwik';
export const HelloWorld = component$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
const click = () => console.log();
return <button onClick$={click}></button>;
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export const HelloWorld = component$(() => {
return 'string';
} else {
return () => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log();
};
}
}
const a = getValue();
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(a);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { component$, useTask$ } from '@builder.io/qwik';
export const HelloWorld = component$(() => {
const a = Symbol();
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(a);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const HelloWorld = component$(() => {
const divRef = useSignal<{ offsetLeft: number }>();

const handleMouseDown = $((e: MouseEvent) => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log('working');
startX = e.pageX - divRef.value!.offsetLeft;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const HelloWorld = component$(() => {
};
const useMethod = getMethod();
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(useMethod);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { component$, useTask$ } from '@builder.io/qwik';

export const HelloWorld = component$(() => {
function useMethod() {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log('stuff');
}
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(useMethod);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default component$(() => {
state.foo = <div>Foo</div>;

useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(state.foo);
});
return <></>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const HelloWorld = component$(() => {
return (
<div
onClick$={() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(a);
}}
></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getFn(): NoSerialize<() => void> {
export const HelloWorld = component$(() => {
const state: Value = { value: 12, fn: getFn() };
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(state.value);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const HelloWorld = component$(() => {
},
};
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(useMethod, obj);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const HelloWorld = component$(() => {
}
const a = getValue();
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(a);
});
return <div></div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const HelloWorld = component$(() => {
};
const useMethod = getMethod();
useTask$(() => {
// eslint-disable-next-line no-console
/* eslint no-console: [, { allow: ["log"] }] */
console.log(useMethod);
});
return <div></div>;
Expand Down
Loading
Loading