eslint-plugin-svelte 2.7.0 → 2.8.0

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 CHANGED
@@ -303,6 +303,7 @@ These rules relate to style guidelines, and are therefore quite subjective:
303
303
 
304
304
  | Rule ID | Description | |
305
305
  |:--------|:------------|:---|
306
+ | [svelte/derived-has-same-inputs-outputs](https://ota-meshi.github.io/eslint-plugin-svelte/rules/derived-has-same-inputs-outputs/) | derived store should use same variable names between values and callback | |
306
307
  | [svelte/first-attribute-linebreak](https://ota-meshi.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak/) | enforce the location of first attribute | :wrench: |
307
308
  | [svelte/html-closing-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-closing-bracket-spacing/) | require or disallow a space before tag's closing brackets | :wrench: |
308
309
  | [svelte/html-quotes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-quotes/) | enforce quotes style of HTML attributes | :wrench: |
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").RuleModule;
2
+ export default _default;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ const svelte_store_1 = require("./reference-helpers/svelte-store");
5
+ exports.default = (0, utils_1.createRule)("derived-has-same-inputs-outputs", {
6
+ meta: {
7
+ docs: {
8
+ description: "derived store should use same variable names between values and callback",
9
+ category: "Stylistic Issues",
10
+ recommended: false,
11
+ conflictWithPrettier: false,
12
+ },
13
+ schema: [],
14
+ messages: {
15
+ unexpected: "The argument name should be '{{name}}'.",
16
+ },
17
+ type: "suggestion",
18
+ },
19
+ create(context) {
20
+ function isIdentifierOrArrayExpression(node) {
21
+ return ["Identifier", "ArrayExpression"].includes(node.type);
22
+ }
23
+ function isFunctionExpression(node) {
24
+ return ["ArrowFunctionExpression", "FunctionExpression"].includes(node.type);
25
+ }
26
+ function checkIdentifier(context, args, fn) {
27
+ const fnParam = fn.params[0];
28
+ if (fnParam.type !== "Identifier")
29
+ return;
30
+ const expectedName = `$${args.name}`;
31
+ if (expectedName !== fnParam.name) {
32
+ context.report({
33
+ node: fn,
34
+ loc: fnParam.loc,
35
+ messageId: "unexpected",
36
+ data: { name: expectedName },
37
+ });
38
+ }
39
+ }
40
+ function checkArrayExpression(context, args, fn) {
41
+ const fnParam = fn.params[0];
42
+ if (fnParam.type !== "ArrayPattern")
43
+ return;
44
+ const argNames = args.elements.map((element) => {
45
+ return element && element.type === "Identifier" ? element.name : null;
46
+ });
47
+ fnParam.elements.forEach((element, index) => {
48
+ const argName = argNames[index];
49
+ if (element && element.type === "Identifier" && argName) {
50
+ const expectedName = `$${argName}`;
51
+ if (expectedName !== element.name) {
52
+ context.report({
53
+ node: fn,
54
+ loc: element.loc,
55
+ messageId: "unexpected",
56
+ data: { name: expectedName },
57
+ });
58
+ }
59
+ }
60
+ });
61
+ }
62
+ return {
63
+ Program() {
64
+ for (const { node } of (0, svelte_store_1.extractStoreReferences)(context, ["derived"])) {
65
+ const [args, fn] = node.arguments;
66
+ if (!args || !isIdentifierOrArrayExpression(args))
67
+ continue;
68
+ if (!fn || !isFunctionExpression(fn))
69
+ continue;
70
+ if (!fn.params || fn.params.length === 0)
71
+ continue;
72
+ if (args.type === "Identifier")
73
+ checkIdentifier(context, args, fn);
74
+ else
75
+ checkArrayExpression(context, args, fn);
76
+ }
77
+ },
78
+ };
79
+ },
80
+ });
@@ -27,7 +27,7 @@ exports.default = (0, utils_1.createRule)("no-store-async", {
27
27
  !fn.async) {
28
28
  continue;
29
29
  }
30
- const start = fn.loc?.start ?? { line: 1, column: 0 };
30
+ const start = fn.loc.start;
31
31
  context.report({
32
32
  node: fn,
33
33
  loc: {
@@ -1,6 +1,8 @@
1
1
  import type * as ESTree from "estree";
2
2
  import type { RuleContext } from "../../types";
3
- export declare function extractStoreReferences(context: RuleContext): Generator<{
3
+ declare type StoreName = "writable" | "readable" | "derived";
4
+ export declare function extractStoreReferences(context: RuleContext, storeNames?: StoreName[]): Generator<{
4
5
  node: ESTree.CallExpression;
5
6
  name: string;
6
7
  }, void>;
8
+ export {};
@@ -2,19 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractStoreReferences = void 0;
4
4
  const eslint_utils_1 = require("eslint-utils");
5
- function* extractStoreReferences(context) {
5
+ function* extractStoreReferences(context, storeNames = ["writable", "readable", "derived"]) {
6
6
  const referenceTracker = new eslint_utils_1.ReferenceTracker(context.getScope());
7
7
  for (const { node, path } of referenceTracker.iterateEsmReferences({
8
8
  "svelte/store": {
9
9
  [eslint_utils_1.ReferenceTracker.ESM]: true,
10
10
  writable: {
11
- [eslint_utils_1.ReferenceTracker.CALL]: true,
11
+ [eslint_utils_1.ReferenceTracker.CALL]: storeNames.includes("writable"),
12
12
  },
13
13
  readable: {
14
- [eslint_utils_1.ReferenceTracker.CALL]: true,
14
+ [eslint_utils_1.ReferenceTracker.CALL]: storeNames.includes("readable"),
15
15
  },
16
16
  derived: {
17
- [eslint_utils_1.ReferenceTracker.CALL]: true,
17
+ [eslint_utils_1.ReferenceTracker.CALL]: storeNames.includes("derived"),
18
18
  },
19
19
  },
20
20
  })) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.rules = void 0;
7
7
  const button_has_type_1 = __importDefault(require("../rules/button-has-type"));
8
8
  const comment_directive_1 = __importDefault(require("../rules/comment-directive"));
9
+ const derived_has_same_inputs_outputs_1 = __importDefault(require("../rules/derived-has-same-inputs-outputs"));
9
10
  const first_attribute_linebreak_1 = __importDefault(require("../rules/first-attribute-linebreak"));
10
11
  const html_closing_bracket_spacing_1 = __importDefault(require("../rules/html-closing-bracket-spacing"));
11
12
  const html_quotes_1 = __importDefault(require("../rules/html-quotes"));
@@ -45,6 +46,7 @@ const valid_compile_1 = __importDefault(require("../rules/valid-compile"));
45
46
  exports.rules = [
46
47
  button_has_type_1.default,
47
48
  comment_directive_1.default,
49
+ derived_has_same_inputs_outputs_1.default,
48
50
  first_attribute_linebreak_1.default,
49
51
  html_closing_bracket_spacing_1.default,
50
52
  html_quotes_1.default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-svelte",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "ESLint plugin for Svelte using AST",
5
5
  "repository": "git+https://github.com/ota-meshi/eslint-plugin-svelte.git",
6
6
  "homepage": "https://ota-meshi.github.io/eslint-plugin-svelte",
@@ -35,6 +35,7 @@
35
35
  "docs:preview": "yarn svelte-kit preview",
36
36
  "docs:watch": "yarn svelte-kit dev",
37
37
  "format-for-gen-file": "eslint src/types-for-node.ts src/utils/rules.ts src/configs --fix",
38
+ "install-with-ignore-engines": "yarn --ignore-engines",
38
39
  "lint": "run-p lint:*",
39
40
  "lint-fix": "yarn lint:es --fix && yarn lint:style --fix",
40
41
  "lint:es": "eslint --cache -f friendly .",
@@ -87,10 +88,10 @@
87
88
  "@changesets/changelog-github": "^0.4.6",
88
89
  "@changesets/cli": "^2.24.2",
89
90
  "@fontsource/fira-mono": "^4.5.0",
90
- "@ota-meshi/eslint-plugin": "^0.11.3",
91
+ "@ota-meshi/eslint-plugin": "^0.12.0",
91
92
  "@sindresorhus/slugify": "^2.1.0",
92
- "@sveltejs/adapter-static": "^1.0.0-next.26",
93
- "@sveltejs/kit": "^1.0.0-next.406",
93
+ "@sveltejs/adapter-static": "^1.0.0-next.40",
94
+ "@sveltejs/kit": "^1.0.0-next.456",
94
95
  "@types/babel__core": "^7.1.19",
95
96
  "@types/cross-spawn": "^6.0.2",
96
97
  "@types/escape-html": "^1.0.2",
@@ -161,10 +162,10 @@
161
162
  "svelte-adapter-ghpages": "0.0.2",
162
163
  "type-coverage": "^2.22.0",
163
164
  "typescript": "^4.5.2",
164
- "vite": "^3.0.0-0",
165
+ "vite": "^3.1.0-0",
165
166
  "vite-plugin-svelte-md": "^0.1.5",
166
167
  "yaml": "^2.1.1",
167
- "yarn-deduplicate": "^5.0.0"
168
+ "yarn-deduplicate": "^6.0.0"
168
169
  },
169
170
  "publishConfig": {
170
171
  "access": "public"