eslint-plugin-svelte 2.1.0 → 2.1.1

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
@@ -331,9 +331,40 @@ Please use GitHub's Issues/PRs.
331
331
 
332
332
  ### Development Tools
333
333
 
334
- - `yarn test` runs tests and measures coverage.
334
+ - `yarn test` runs tests.
335
+ - `yarn cover` runs tests and measures coverage.
335
336
  - `yarn update` runs in order to update readme and recommended configuration.
336
337
 
338
+ ### Test the Rule
339
+
340
+ Rule testing almost always uses fixtures.
341
+ For example, for an `indent` rule, the `.ts` file that runs the test is `tests/src/rules/indent.ts` and the fixture is in `tests/fixtures/rules/indent`.
342
+ The fixture directory has an `invalid` directory and a `valid` directory.
343
+
344
+ - The `invalid` directory contains test cases where the rule reports problems.
345
+ - The `valid` directory contains test cases where the rule does not report a problem.
346
+
347
+ The fixture input file should be named `*-input.svelte`. It is automatically collected and tested.
348
+ If your test requires configuration, you need to add a json file with the configuration.
349
+
350
+ - If you want to apply a configuration to `my-test-input.svelte`, add `my-test-config.json`.
351
+ - If you want to apply the same configuration to all the fixtures in that directory, add `_config.json`.
352
+
353
+ To verify the output of invalid test cases requires `*-errors.json`, and `*-output.svelte` (for auto-fix). However, you don't have to add them yourself. If they do not exist, they will be automatically generated when you run the test. In other words, delete them manually when you want to recreate them.
354
+
355
+ **Tips**:
356
+
357
+ If you want to test only one rule, run the following command (for `indent` rule):
358
+
359
+ ```sh
360
+ yarn test -g indent
361
+ ```
362
+
363
+ Take https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha as reference for details.
364
+
365
+ If you want to test only `my-test-input.svelte`, add `my-test-config.json` and save `{"only": true}`.
366
+ (Note that `{"only": true}` must be removed before making a pull request.)
367
+
337
368
  ### Working With Rules
338
369
 
339
370
  This plugin uses [svelte-eslint-parser](https://github.com/ota-meshi/svelte-eslint-parser) for the parser. Check [here](https://ota-meshi.github.io/svelte-eslint-parser/) to find out about AST.
@@ -229,8 +229,9 @@ exports.default = (0, utils_1.createRule)("prefer-class-directive", {
229
229
  report(node, map, attr);
230
230
  }
231
231
  return {
232
- "SvelteElement > SvelteStartTag > SvelteAttribute"(node) {
233
- if (node.key.name !== "class") {
232
+ "SvelteStartTag > SvelteAttribute"(node) {
233
+ if (!(0, ast_utils_1.isHTMLElementLike)(node.parent.parent) ||
234
+ node.key.name !== "class") {
234
235
  return;
235
236
  }
236
237
  for (let index = 0; index < node.value.length; index++) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("../utils");
4
4
  const css_utils_1 = require("../utils/css-utils");
5
+ const ast_utils_1 = require("../utils/ast-utils");
5
6
  function isStringLiteral(node) {
6
7
  return node.type === "Literal" && typeof node.value === "string";
7
8
  }
@@ -140,7 +141,8 @@ exports.default = (0, utils_1.createRule)("prefer-style-directive", {
140
141
  }
141
142
  return {
142
143
  "SvelteStartTag > SvelteAttribute"(node) {
143
- if (!isHTMLElement(node.parent.parent) || node.key.name !== "style") {
144
+ if (!(0, ast_utils_1.isHTMLElementLike)(node.parent.parent) ||
145
+ node.key.name !== "style") {
144
146
  return;
145
147
  }
146
148
  const root = (0, css_utils_1.parseStyleAttributeValue)(node, context);
@@ -149,16 +151,5 @@ exports.default = (0, utils_1.createRule)("prefer-style-directive", {
149
151
  }
150
152
  },
151
153
  };
152
- function isHTMLElement(node) {
153
- if (node.type === "SvelteElement") {
154
- if (node.kind === "html") {
155
- return true;
156
- }
157
- if (node.kind === "special") {
158
- return node.name.name === "svelte:element";
159
- }
160
- }
161
- return false;
162
- }
163
154
  },
164
155
  });
@@ -5,6 +5,11 @@ import type { Scope } from "eslint";
5
5
  export declare function equalTokens(left: ASTNode, right: ASTNode, sourceCode: SourceCode): boolean;
6
6
  export declare function getStringIfConstant(node: ESTree.Expression): string | null;
7
7
  export declare function needParentheses(node: ESTree.Expression, kind: "not" | "logical"): boolean;
8
+ export declare function isHTMLElementLike(node: SvAST.SvelteElement | SvAST.SvelteScriptElement | SvAST.SvelteStyleElement): node is SvAST.SvelteHTMLElement | (SvAST.SvelteSpecialElement & {
9
+ name: SvAST.SvelteName & {
10
+ name: "svelte:element";
11
+ };
12
+ });
8
13
  export declare function findAttribute<N extends string>(node: SvAST.SvelteElement | SvAST.SvelteScriptElement | SvAST.SvelteStyleElement | SvAST.SvelteStartTag, name: N): (SvAST.SvelteAttribute & {
9
14
  key: SvAST.SvelteAttribute["key"] & {
10
15
  name: N;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getMustacheTokens = exports.getAttributeValueQuoteAndRange = exports.getScope = exports.findVariable = exports.getLangValue = exports.getStaticAttributeValue = exports.findBindDirective = exports.findShorthandAttribute = exports.findAttribute = exports.needParentheses = exports.getStringIfConstant = exports.equalTokens = void 0;
26
+ exports.getMustacheTokens = exports.getAttributeValueQuoteAndRange = exports.getScope = exports.findVariable = exports.getLangValue = exports.getStaticAttributeValue = exports.findBindDirective = exports.findShorthandAttribute = exports.findAttribute = exports.isHTMLElementLike = exports.needParentheses = exports.getStringIfConstant = exports.equalTokens = void 0;
27
27
  const eslintUtils = __importStar(require("eslint-utils"));
28
28
  function equalTokens(left, right, sourceCode) {
29
29
  const tokensL = sourceCode.getTokens(left);
@@ -95,6 +95,20 @@ function needParentheses(node, kind) {
95
95
  return false;
96
96
  }
97
97
  exports.needParentheses = needParentheses;
98
+ function isHTMLElementLike(node) {
99
+ if (node.type !== "SvelteElement") {
100
+ return false;
101
+ }
102
+ switch (node.kind) {
103
+ case "html":
104
+ return true;
105
+ case "special":
106
+ return node.name.name === "svelte:element";
107
+ default:
108
+ return false;
109
+ }
110
+ }
111
+ exports.isHTMLElementLike = isHTMLElementLike;
98
112
  function findAttribute(node, name) {
99
113
  const startTag = node.type === "SvelteStartTag" ? node : node.startTag;
100
114
  for (const attr of startTag.attributes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-svelte",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
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",
@@ -77,7 +77,7 @@
77
77
  "@ota-meshi/eslint-plugin": "^0.11.0",
78
78
  "@sindresorhus/slugify": "^2.1.0",
79
79
  "@sveltejs/adapter-static": "^1.0.0-next.26",
80
- "@sveltejs/kit": "^1.0.0-next.240",
80
+ "@sveltejs/kit": "1.0.0-next.358",
81
81
  "@types/babel__core": "^7.1.19",
82
82
  "@types/eslint": "^8.0.0",
83
83
  "@types/eslint-scope": "^3.7.0",
@@ -122,7 +122,7 @@
122
122
  "pirates": "^4.0.1",
123
123
  "postcss-nested": "^5.0.6",
124
124
  "prettier": "^2.2.1",
125
- "prettier-plugin-pkg": "^0.15.0",
125
+ "prettier-plugin-pkg": "^0.16.0",
126
126
  "prettier-plugin-svelte": "^2.6.0",
127
127
  "prism-svelte": "^0.5.0",
128
128
  "prismjs": "^1.25.0",