Socket
Socket
Sign inDemoInstall

svelte-eslint-parser

Package Overview
Dependencies
Maintainers
1
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-eslint-parser - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

1

lib/context/index.js

@@ -104,2 +104,3 @@ "use strict";

];
// eslint-disable-next-line regexp/no-unused-capturing-group -- maybe bug
const attrRe = /(<key>[^\s=]+)(?:=(?:"(<val>[^"]*)"|'(<val>[^"]*)'|(<val>[^\s=]+)))?/giu;

@@ -106,0 +107,0 @@ const attrs = {};

@@ -6,5 +6,7 @@ import type { Scope, ScopeManager } from "eslint-scope";

currentScope: Scope;
private readonly nodeToScope;
constructor(scopeManager: ScopeManager);
nestBlockScope(node: any, type: "block" | "for" | "catch"): void;
closeScope(): void;
registerScope(scope: Scope): void;
}

@@ -10,2 +10,51 @@ "use strict";

this.currentScope = moduleScope;
// transform scopeManager
const nodeToScope = (this.nodeToScope = new WeakMap());
for (const scope of this.scopeManager.scopes) {
const scopes = this.nodeToScope.get(scope.block);
if (scopes) {
scopes.push(scope);
}
else {
this.nodeToScope.set(scope.block, [scope]);
}
}
this.scopeManager.acquire = function (node, inner) {
/**
* predicate
*/
function predicate(testScope) {
if (testScope.type === "function" &&
testScope.functionExpressionScope) {
return false;
}
return true;
}
const scopes = nodeToScope.get(node);
if (!scopes || scopes.length === 0) {
return null;
}
// Heuristic selection from all scopes.
// If you would like to get all scopes, please use ScopeManager#acquireAll.
if (scopes.length === 1) {
return scopes[0];
}
if (inner) {
for (let i = scopes.length - 1; i >= 0; --i) {
const scope = scopes[i];
if (predicate(scope)) {
return scope;
}
}
}
else {
for (let i = 0, iz = scopes.length; i < iz; ++i) {
const scope = scopes[i];
if (predicate(scope)) {
return scope;
}
}
}
return null;
};
}

@@ -28,9 +77,19 @@ nestBlockScope(node, type) {

this.currentScope = newScope;
this.scopeManager.scopes.push(newScope);
// variableScope = (this.type === "global" || this.type === "function" || this.type === "module") ? this : upperScope.variableScope;
}
closeScope() {
this.registerScope(this.currentScope);
this.currentScope = this.currentScope.upper;
}
registerScope(scope) {
this.scopeManager.scopes.push(scope);
const scopes = this.nodeToScope.get(scope.block);
if (scopes) {
scopes.push(scope);
}
else {
this.nodeToScope.set(scope.block, [scope]);
}
}
}
exports.TemplateScopeManager = TemplateScopeManager;

@@ -92,2 +92,9 @@ "use strict";

if (variable) {
// It does not write directly to the original variable.
// Therefore, this variable is always a reference.
reference.isWrite = () => false;
reference.isWriteOnly = () => false;
reference.isReadWrite = () => false;
reference.isReadOnly = () => true;
reference.isRead = () => true;
variable.references.push(reference);

@@ -94,0 +101,0 @@ reference.resolved = variable;

2

lib/parser/converts/es.js

@@ -452,3 +452,3 @@ "use strict";

for (const scope of targetScope.childScopes) {
templateScopeManager.scopeManager.scopes.push(scope);
templateScopeManager.registerScope(scope);
templateScopeManager.currentScope.childScopes.push(scope);

@@ -455,0 +455,0 @@ scope.upper = templateScopeManager.currentScope;

{
"name": "svelte-eslint-parser",
"version": "0.0.1",
"version": "0.0.2",
"description": "Svelte parser for ESLint",

@@ -19,3 +19,4 @@ "main": "lib/index.js",

"preversion": "npm run lint && npm test",
"update-fixtures": "ts-node --transpile-only ./tools/update-fixtures.ts"
"update-fixtures": "ts-node --transpile-only ./tools/update-fixtures.ts",
"eslint-playground": "eslint tests/fixtures --ext .svelte --config .eslintrc-for-playground.js --format codeframe"
},

@@ -47,3 +48,3 @@ "repository": {

"devDependencies": {
"@ota-meshi/eslint-plugin": "^0.4.0",
"@ota-meshi/eslint-plugin": "^0.6.0",
"@types/eslint": "^7.2.0",

@@ -61,3 +62,3 @@ "@types/eslint-scope": "^3.7.0",

"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-json-schema-validator": "^0.4.0",
"eslint-plugin-json-schema-validator": "^1.0.0",
"eslint-plugin-jsonc": "^1.0.0",

@@ -64,0 +65,0 @@ "eslint-plugin-node": "^11.1.0",

@@ -5,10 +5,21 @@ # svelte-eslint-parser

***Works In Progress***
***This parser is still in an EXPERIMENTAL STATE***
::: ***WORKS IN PROGRESS*** :::
::: ***This Parser is still in an EXPERIMENTAL STATE*** :::
[![NPM license](https://img.shields.io/npm/l/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser)
[![NPM version](https://img.shields.io/npm/v/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser)
[![NPM downloads](https://img.shields.io/badge/dynamic/json.svg?label=downloads&colorB=green&suffix=/day&query=$.downloads&uri=https://api.npmjs.org//downloads/point/last-day/svelte-eslint-parser&maxAge=3600)](http://www.npmtrends.com/svelte-eslint-parser)
[![NPM downloads](https://img.shields.io/npm/dw/svelte-eslint-parser.svg)](http://www.npmtrends.com/svelte-eslint-parser)
[![NPM downloads](https://img.shields.io/npm/dm/svelte-eslint-parser.svg)](http://www.npmtrends.com/svelte-eslint-parser)
[![NPM downloads](https://img.shields.io/npm/dy/svelte-eslint-parser.svg)](http://www.npmtrends.com/svelte-eslint-parser)
[![NPM downloads](https://img.shields.io/npm/dt/svelte-eslint-parser.svg)](http://www.npmtrends.com/svelte-eslint-parser)
[![Build Status](https://github.com/ota-meshi/svelte-eslint-parser/workflows/CI/badge.svg?branch=master)](https://github.com/ota-meshi/svelte-eslint-parser/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/ota-meshi/svelte-eslint-parser/badge.svg?branch=master)](https://coveralls.io/github/ota-meshi/svelte-eslint-parser?branch=master)
## ❓ Why?
[Svelte] has the official ESLint plugin [eslint-plugin-svelte3]. [eslint-plugin-svelte3] works well enough to check scripts. However, it does not handle the AST of the template, which makes it very difficult for third parties to create their own [ESLint] rules for [Svelte].
[Svelte] has the official ESLint plugin the [eslint-plugin-svelte3]. The [eslint-plugin-svelte3] works well enough to check scripts. However, it does not handle the AST of the template, which makes it very difficult for third parties to create their own the [ESLint] rules for the [Svelte].
The `svelte-eslint-parser` aims to make it easy to create your own rules for [Svelte] by allowing the template AST to be used in the rules.
The `svelte-eslint-parser` aims to make it easy to create your own rules for the [Svelte] by allowing the template AST to be used in the rules.

@@ -24,3 +35,3 @@ ## 💿 Installation

1. Write `overrides.parser` option into your `.eslintrc.*` file.
2. Use glob patterns or `--ext .vue` CLI option.
2. Use glob patterns or `--ext .svelte` CLI option.

@@ -100,2 +111,7 @@ ```json

## Usage for Custom Rules / Plugins
- [AST.md](./docs/AST.md) is AST specification.
- You can see the AST on the [Online DEMO](https://ota-meshi.github.io/svelte-eslint-parser/).
## :beers: Contributing

@@ -102,0 +118,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc