eslint-plugin-qwik 0.0.18-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/index.js +9 -0
- package/lib/noPropsDestructuting.js +32 -0
- package/lib/noUseAfterAwait.js +46 -0
- package/package.json +27 -0
- package/qwik.unit.js +51 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# eslint-plugin-qwik
|
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.rules = void 0;
|
|
4
|
+
var noPropsDestructuting_1 = require("./lib/noPropsDestructuting");
|
|
5
|
+
var noUseAfterAwait_1 = require("./lib/noUseAfterAwait");
|
|
6
|
+
exports.rules = {
|
|
7
|
+
'no-props-destructuring': noPropsDestructuting_1.noPropsDestructuring,
|
|
8
|
+
'no-use-after-await': noUseAfterAwait_1.noUseAfterAwait
|
|
9
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright Builder.io, Inc. All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
8
|
+
* found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
exports.__esModule = true;
|
|
11
|
+
exports.noPropsDestructuring = void 0;
|
|
12
|
+
exports.noPropsDestructuring = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Object destructuring is not recomended for component$',
|
|
17
|
+
category: 'Variables',
|
|
18
|
+
recommended: true,
|
|
19
|
+
url: 'https://github.com/BuilderIO/qwik'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
create: function (context) {
|
|
23
|
+
return {
|
|
24
|
+
"CallExpression[callee.name='component$'][arguments.0.params.0.type='ObjectPattern']": function (node) {
|
|
25
|
+
context.report({
|
|
26
|
+
node: node,
|
|
27
|
+
message: 'Props destructuring is not a good practice in Qwik'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright Builder.io, Inc. All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
8
|
+
* found in the LICENSE file at https://github.com/BuilderIO/qwik/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
exports.__esModule = true;
|
|
11
|
+
exports.noUseAfterAwait = void 0;
|
|
12
|
+
exports.noUseAfterAwait = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Object destructuring is not recomended for component$',
|
|
17
|
+
category: 'Variables',
|
|
18
|
+
recommended: true,
|
|
19
|
+
url: 'https://github.com/BuilderIO/qwik'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
create: function (context) {
|
|
23
|
+
var stack = [];
|
|
24
|
+
return {
|
|
25
|
+
ArrowFunctionExpression: function () {
|
|
26
|
+
stack.push({ await: false });
|
|
27
|
+
},
|
|
28
|
+
'ArrowFunctionExpression:exit': function () {
|
|
29
|
+
stack.pop();
|
|
30
|
+
},
|
|
31
|
+
AwaitExpression: function () {
|
|
32
|
+
var last = stack[stack.length - 1];
|
|
33
|
+
last.await = true;
|
|
34
|
+
},
|
|
35
|
+
'CallExpression[callee.name=/^use/]': function (node) {
|
|
36
|
+
var last = stack[stack.length - 1];
|
|
37
|
+
if (last.await) {
|
|
38
|
+
context.report({
|
|
39
|
+
node: node,
|
|
40
|
+
message: 'Calling use* methods after await is not safe.'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-qwik",
|
|
3
|
+
"version": "0.0.18-6",
|
|
4
|
+
"description": "An Open-Source sub-framework designed with a focus on server-side-rendering, lazy-loading, and styling/animation.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"eslint": ">= 8"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/BuilderIO/qwik#readme",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/BuilderIO/qwik.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/BuilderIO/qwik/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"builder.io",
|
|
21
|
+
"qwik",
|
|
22
|
+
"eslint"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=14"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/qwik.unit.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
var RuleTester = require('eslint').RuleTester;
|
|
6
|
+
var index_1 = require("./index");
|
|
7
|
+
var testConfig = {
|
|
8
|
+
env: {
|
|
9
|
+
es6: true
|
|
10
|
+
},
|
|
11
|
+
parserOptions: {
|
|
12
|
+
ecmaFeatures: {
|
|
13
|
+
jsx: true
|
|
14
|
+
},
|
|
15
|
+
ecmaVersion: 2021,
|
|
16
|
+
sourceType: 'module'
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
describe('no-props-destructuring', function () {
|
|
20
|
+
var ruleTester = new RuleTester(testConfig);
|
|
21
|
+
ruleTester.run('my-rule', index_1.rules['no-props-destructuring'], {
|
|
22
|
+
valid: [
|
|
23
|
+
"export const HelloWorld = component$((props) => {\n return $(({prop}) => {\n return (\n <Host>\n {prop}\n {props}\n </Host>\n );\n });\n });",
|
|
24
|
+
],
|
|
25
|
+
invalid: [
|
|
26
|
+
{
|
|
27
|
+
code: "export const HelloWorld = component$(({prop}) => {\n return $(() => {\n return (\n <Host>\n {prop}\n </Host>\n );\n });\n });",
|
|
28
|
+
errors: ['Props destructuring is not a good practice in Qwik']
|
|
29
|
+
},
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('no-use-after-await', function () {
|
|
34
|
+
var ruleTester = new RuleTester(testConfig);
|
|
35
|
+
ruleTester.run('my-rule', index_1.rules['no-use-after-await'], {
|
|
36
|
+
valid: [
|
|
37
|
+
"export const HelloWorld = component$(async () => {\n useMethod();\n await something();\n return $(() => {\n return <Host></Host>\n });\n });",
|
|
38
|
+
"export const HelloWorld = component$(async () => {\n useMethod();\n await something();\n await stuff();\n return $(() => {\n useHostElement();\n return <Host></Host>\n });\n });",
|
|
39
|
+
],
|
|
40
|
+
invalid: [
|
|
41
|
+
{
|
|
42
|
+
code: "export const HelloWorld = component$(async () => {\n await something();\n useMethod();\n return $(() => {\n return (\n <Host>\n {prop}\n </Host>\n );\n });\n });",
|
|
43
|
+
errors: ['Calling use* methods after await is not safe.']
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
code: "export const HelloWorld = component$(async () => {\n if (stuff) {\n await something();\n }\n useMethod();\n return $(() => {\n return (\n <Host>\n {prop}\n </Host>\n );\n });\n });",
|
|
47
|
+
errors: ['Calling use* methods after await is not safe.']
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
});
|