Skip to content

Commit

Permalink
update parser and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Dec 2, 2024
1 parent d3fd17c commit 7bae80a
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 135 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Example **eslint.config.js**:
import eslintPluginSvelte from 'eslint-plugin-svelte';
import svelteConfig from './svelte.config.js';
export default [
...eslintPluginSvelte.configs['flat/recommended'],
...eslintPluginSvelte.configs.recommended,
{
files: [
'**/*.svelte',
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Example **eslint.config.js**:
import eslintPluginSvelte from 'eslint-plugin-svelte';
import svelteConfig from './svelte.config.js';
export default [
...eslintPluginSvelte.configs['flat/recommended'],
...eslintPluginSvelte.configs.recommended,
{
files: [
'**/*.svelte',
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"postcss-safe-parser": "^6.0.0",
"postcss-selector-parser": "^7.0.0",
"semver": "^7.6.3",
"svelte-eslint-parser": "^1.0.0-next.1"
"svelte-eslint-parser": "^1.0.0-next.3"
},
"devDependencies": {
"@babel/core": "^7.26.0",
Expand Down
46 changes: 4 additions & 42 deletions packages/eslint-plugin-svelte/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,6 @@
import './rule-types.js';
import type { RuleModule } from './types.js';
import { rules as ruleList } from './utils/rules.js';
import base, { setPluginObject } from './configs/flat/base.js';
import recommended from './configs/flat/recommended.js';
import prettier from './configs/flat/prettier.js';
import all from './configs/flat/all.js';
import * as processor from './processor/index.js';
import * as meta from './meta.js';
import * as plugin from './main.js';
import { setPluginObject } from './configs/flat/base.js';
setPluginObject(plugin);

export const configs = {
base,
recommended,
prettier,
all,
// For backward compatibility
'flat/base': base,
'flat/recommended': recommended,
'flat/prettier': prettier,
'flat/all': all
};

export const rules = ruleList.reduce(
(obj, r) => {
obj[r.meta.docs.ruleName] = r;
return obj;
},
{} as { [key: string]: RuleModule }
);

export { meta };
export const processors = {
'.svelte': processor,
svelte: processor
};

const plugin = {
rules,
configs,
meta,
processors
};
setPluginObject(plugin as never);
export * from './main.js';
export default plugin;
36 changes: 36 additions & 0 deletions packages/eslint-plugin-svelte/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import './rule-types.js';
import type { RuleModule } from './types.js';
import { rules as ruleList } from './utils/rules.js';
import base from './configs/flat/base.js';
import recommended from './configs/flat/recommended.js';
import prettier from './configs/flat/prettier.js';
import all from './configs/flat/all.js';
import * as processor from './processor/index.js';
import * as metaModule from './meta.js';
import type { Rule } from 'eslint';

export const configs = {
base,
recommended,
prettier,
all,
// For backward compatibility
'flat/base': base,
'flat/recommended': recommended,
'flat/prettier': prettier,
'flat/all': all
};

export const rules = ruleList.reduce(
(obj, r) => {
obj[r.meta.docs.ruleName] = r;
return obj;
},
{} as { [key: string]: RuleModule }
) as unknown as Record<string, Rule.RuleModule>;

export const meta = { ...metaModule };
export const processors = {
'.svelte': processor,
svelte: processor
};
85 changes: 85 additions & 0 deletions packages/eslint-plugin-svelte/src/type-defs/estree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// IMPORTANT!
// This file has been automatically generated,
// in order to update its content execute "pnpm run update"
//
// Replace type information to use "@typescript-eslint/types" instead of "estree".
//
declare module 'estree' {
import type { TSESTree } from '@typescript-eslint/types';

export type Node = TSESTree.Node;
export type Program = TSESTree.Program;
export type Expression = TSESTree.Expression;
export type Statement = TSESTree.Statement;
export type Pattern = TSESTree.DestructuringPattern;
export type AccessorProperty = TSESTree.AccessorProperty;
export type ArrayExpression = TSESTree.ArrayExpression;
export type ArrayPattern = TSESTree.ArrayPattern;
export type ArrowFunctionExpression = TSESTree.ArrowFunctionExpression;
export type AssignmentExpression = TSESTree.AssignmentExpression;
export type AssignmentPattern = TSESTree.AssignmentPattern;
export type AwaitExpression = TSESTree.AwaitExpression;
export type BinaryExpression = TSESTree.BinaryExpression;
export type BlockStatement = TSESTree.BlockStatement;
export type BreakStatement = TSESTree.BreakStatement;
export type CallExpression = TSESTree.CallExpression;
export type CatchClause = TSESTree.CatchClause;
export type ChainExpression = TSESTree.ChainExpression;
export type ClassBody = TSESTree.ClassBody;
export type ClassDeclaration = TSESTree.ClassDeclaration;
export type ClassExpression = TSESTree.ClassExpression;
export type ConditionalExpression = TSESTree.ConditionalExpression;
export type ContinueStatement = TSESTree.ContinueStatement;
export type DebuggerStatement = TSESTree.DebuggerStatement;
export type DoWhileStatement = TSESTree.DoWhileStatement;
export type EmptyStatement = TSESTree.EmptyStatement;
export type ExportAllDeclaration = TSESTree.ExportAllDeclaration;
export type ExportDefaultDeclaration = TSESTree.ExportDefaultDeclaration;
export type ExportNamedDeclaration = TSESTree.ExportNamedDeclaration;
export type ExportSpecifier = TSESTree.ExportSpecifier;
export type ExpressionStatement = TSESTree.ExpressionStatement;
export type ForInStatement = TSESTree.ForInStatement;
export type ForOfStatement = TSESTree.ForOfStatement;
export type ForStatement = TSESTree.ForStatement;
export type FunctionDeclaration = TSESTree.FunctionDeclaration;
export type FunctionExpression = TSESTree.FunctionExpression;
export type Identifier = TSESTree.Identifier;
export type IfStatement = TSESTree.IfStatement;
export type ImportDeclaration = TSESTree.ImportDeclaration;
export type ImportDefaultSpecifier = TSESTree.ImportDefaultSpecifier;
export type ImportExpression = TSESTree.ImportExpression;
export type ImportNamespaceSpecifier = TSESTree.ImportNamespaceSpecifier;
export type ImportSpecifier = TSESTree.ImportSpecifier;
export type LabeledStatement = TSESTree.LabeledStatement;
export type Literal = TSESTree.Literal;
export type LogicalExpression = TSESTree.LogicalExpression;
export type MemberExpression = TSESTree.MemberExpression;
export type MetaProperty = TSESTree.MetaProperty;
export type MethodDefinition = TSESTree.MethodDefinition;
export type NewExpression = TSESTree.NewExpression;
export type ObjectExpression = TSESTree.ObjectExpression;
export type ObjectPattern = TSESTree.ObjectPattern;
export type PrivateIdentifier = TSESTree.PrivateIdentifier;
export type Property = TSESTree.Property;
export type PropertyDefinition = TSESTree.PropertyDefinition;
export type RestElement = TSESTree.RestElement;
export type ReturnStatement = TSESTree.ReturnStatement;
export type SequenceExpression = TSESTree.SequenceExpression;
export type SpreadElement = TSESTree.SpreadElement;
export type Super = TSESTree.Super;
export type SwitchCase = TSESTree.SwitchCase;
export type SwitchStatement = TSESTree.SwitchStatement;
export type TaggedTemplateExpression = TSESTree.TaggedTemplateExpression;
export type TemplateElement = TSESTree.TemplateElement;
export type TemplateLiteral = TSESTree.TemplateLiteral;
export type ThisExpression = TSESTree.ThisExpression;
export type ThrowStatement = TSESTree.ThrowStatement;
export type TryStatement = TSESTree.TryStatement;
export type UnaryExpression = TSESTree.UnaryExpression;
export type UpdateExpression = TSESTree.UpdateExpression;
export type VariableDeclaration = TSESTree.VariableDeclaration;
export type VariableDeclarator = TSESTree.VariableDeclarator;
export type WhileStatement = TSESTree.WhileStatement;
export type WithStatement = TSESTree.WithStatement;
export type YieldExpression = TSESTree.YieldExpression;
}
5 changes: 3 additions & 2 deletions packages/eslint-plugin-svelte/tools/update-types-for-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const __dirname = path.dirname(new URL(import.meta.url).pathname);
// const filename = fileURLToPath(import.meta.url)
const dirname = __dirname; // path.dirname(filename)
const typesForNodeFilename = path.join(dirname, '../src/types-for-node.ts');
const estreeFilename = path.join(dirname, '../typings/estree/index.d.ts');
const estreeFilename = path.join(dirname, '../src/type-defs/estree.d.ts');
const { visitorKeys } = parseForESLint('');

const esNextNodeNames = ['Decorator', 'ImportAttribute', 'StaticBlock'];
Expand All @@ -32,7 +32,7 @@ const estreeCode = [
//
// Replace type information to use "@typescript-eslint/types" instead of "estree".
//
declare module 'estree' {
import type { TSESTree } from "@typescript-eslint/types"
export type Node = TSESTree.Node
Expand Down Expand Up @@ -112,5 +112,6 @@ for (const nodeType of svelteNodeNames.filter((k) => !esSvelteNodeNames.includes
}
typesForNodeCode.push(`}`);

estreeCode.push(`}`);
void writeAndFormat(typesForNodeFilename, typesForNodeCode.join('\n'));
void writeAndFormat(estreeFilename, estreeCode.join('\n'));
4 changes: 0 additions & 4 deletions packages/eslint-plugin-svelte/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"baseUrl": ".",
"esModuleInterop": true,
"outDir": "lib",
"paths": {
"*": ["typings/*"]
},
"skipLibCheck": true,
"resolveJsonModule": true
},
Expand All @@ -30,7 +27,6 @@
"tools/**/*",
"vite.config.mts",
"docs-svelte-kit/**/*.mts"
// "typings/**/*"
],
"exclude": ["lib/**/*", "tests/fixtures/**/*"]
}
84 changes: 0 additions & 84 deletions packages/eslint-plugin-svelte/typings/estree/index.d.ts

This file was deleted.

0 comments on commit 7bae80a

Please sign in to comment.