Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(website): rewrite WebLinter to typescript and fix support for ts 4.7#5034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 8 commits intomainfromfeat/refactor-and-convert-sandbox-to-ts
May 24, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionspackages/utils/src/ts-eslint/Linter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ declare class LinterBase {

/**
* Performs multiple autofix passes over the text until as many fixes as possible have been applied.
* @paramtext The source text to apply fixes to.
* @paramcode The source text to apply fixes to.
* @param config The ESLint config object to use.
* @param options The ESLint options object to use.
* @returns The result of the fix operation as returned from the SourceCodeFixer.
Expand DownExpand Up@@ -316,7 +316,7 @@ namespace Linter {

export interface ESLintParseResult {
ast: TSESTree.Program;
parserServices?: ParserServices;
services?: ParserServices;
scopeManager?: Scope.ScopeManager;
visitorKeys?: SourceCode.VisitorKeys;
}
Expand Down
92 changes: 0 additions & 92 deletionspackages/website-eslint/src/linter/CompilerHost.js
View file
Open in desktop

This file was deleted.

74 changes: 8 additions & 66 deletionspackages/website-eslint/src/linter/linter.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,16 @@
import 'vs/language/typescript/tsWorker';
import { parseForESLint } from './parser';
import { Linter } from 'eslint';
import rules from '@typescript-eslint/eslint-plugin/dist/rules';

const PARSER_NAME = '@typescript-eslint/parser';

export function loadLinter(libs, options) {
export function createLinter() {
const linter = new Linter();
let storedAST;
let storedTsAST;
let storedScope;

let compilerOptions = options;

linter.defineParser(PARSER_NAME, {
parseForESLint(code, eslintOptions) {
const toParse = parseForESLint(
code,
eslintOptions,
compilerOptions,
libs,
);
storedAST = toParse.ast;
storedTsAST = toParse.tsAst;
storedScope = toParse.scopeManager;
return toParse;
},
// parse(code: string, options: ParserOptions): ParseForESLintResult['ast'] {
// const toParse = parseForESLint(code, options);
// storedAST = toParse.ast;
// return toParse.ast;
// },
});

for (const name of Object.keys(rules)) {
for (const name in rules) {
linter.defineRule(`@typescript-eslint/${name}`, rules[name]);
}

const ruleNames = Array.from(linter.getRules()).map(value => {
return {
name: value[0],
description: value[1]?.meta?.docs?.description,
};
});

return {
ruleNames: ruleNames,

updateOptions(options) {
compilerOptions = options || {};
},

getScope() {
return storedScope;
},

getAst() {
return storedAST;
},

getTsAst() {
return storedTsAST;
},

lint(code, parserOptions, rules) {
return linter.verify(code, {
parser: PARSER_NAME,
parserOptions,
rules,
});
},
};
return linter;
}

export { analyze } from '@typescript-eslint/scope-manager/dist/analyze';
export { visitorKeys } from '@typescript-eslint/visitor-keys/dist/visitor-keys';
export { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter';
export { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind';
62 changes: 0 additions & 62 deletionspackages/website-eslint/src/linter/parser.js
View file
Open in desktop

This file was deleted.

49 changes: 12 additions & 37 deletionspackages/website-eslint/types/index.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import type { ParserOptions } from '@typescript-eslint/types';
import type { SourceFile, CompilerOptions } from 'typescript';

export type LintMessage = TSESLint.Linter.LintMessage;
export type RuleFix = TSESLint.RuleFix;
export type RulesRecord = TSESLint.Linter.RulesRecord;
export type RuleEntry = TSESLint.Linter.RuleEntry;

export interface WebLinter {
ruleNames: { name: string; description?: string }[];

getAst(): TSESTree.Program;
getTsAst(): SourceFile;
getScope(): Record<string, unknown>;
updateOptions(options?: Record<string, unknown>): void;

lint(
code: string,
parserOptions: ParserOptions,
rules?: RulesRecord,
): LintMessage[];
import type { TSESLint } from '@typescript-eslint/utils';

import { analyze } from '@typescript-eslint/scope-manager/dist/analyze';
import { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter';
import { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind';

export interface LintUtils {
createLinter: () => TSESLint.Linter;
analyze: typeof analyze;
visitorKeys: TSESLint.SourceCode.VisitorKeys;
astConverter: typeof astConverter;
getScriptKind: typeof getScriptKind;
}

export interface LinterLoader {
loadLinter(
libMap: Map<string, string>,
compilerOptions: CompilerOptions,
): WebLinter;
}

export type {
DebugLevel,
EcmaVersion,
ParserOptions,
SourceType,
TSESTree,
} from '@typescript-eslint/types';
2 changes: 1 addition & 1 deletionpackages/website/src/components/ASTViewerESTree.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';

import ASTViewer from './ast/ASTViewer';
import type { ASTViewerBaseProps, ASTViewerModelMap } from './ast/types';
import type { TSESTree } from '@typescript-eslint/website-eslint';
import type { TSESTree } from '@typescript-eslint/utils';
import { serialize } from './ast/serializer/serializer';
import { createESTreeSerializer } from './ast/serializer/serializerESTree';

Expand Down
4 changes: 2 additions & 2 deletionspackages/website/src/components/Playground.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ import ASTViewerTS from './ASTViewerTS';

import type { RuleDetails, SelectedRange } from './types';

import type { TSESTree } from '@typescript-eslint/website-eslint';
import type { TSESTree } from '@typescript-eslint/utils';
import type { SourceFile } from 'typescript';
import ASTViewerScope from '@site/src/components/ASTViewerScope';

Expand All@@ -44,7 +44,7 @@ function Playground(): JSX.Element {
showAST: false,
sourceType: 'module',
code: '',
ts: process.env.TS_VERSION,
ts: process.env.TS_VERSION!,
rules: {},
tsConfig: {},
});
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import type { ASTViewerModel, Serializer } from '../types';
import type { TSESTree } from '@typescript-eslint/utils';
import { isRecord } from '../utils';
import type { TSESTree } from '@typescript-eslint/website-eslint';

export const propsToFilter = ['parent', 'comments', 'tokens'];

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import type { ASTViewerModel, Serializer, SelectedRange } from '../types';
import type { TSESTree } from '@typescript-eslint/website-eslint';
import type { TSESTree } from '@typescript-eslint/utils';
import { isRecord } from '../utils';

function isESTreeNode(
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@ export const propsToFilter = [
'jsDocComment',
'lineMap',
'externalModuleIndicator',
'setExternalModuleIndicator',
'bindDiagnostics',
'transformFlags',
'resolvedModules',
Expand Down
3 changes: 1 addition & 2 deletionspackages/website/src/components/config/ConfigEslint.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
import React, { useCallback, useEffect, useState } from 'react';
import type { RulesRecord, RuleEntry } from '@typescript-eslint/website-eslint';

import ConfigEditor, { ConfigOptionsType } from './ConfigEditor';
import type { RuleDetails } from '../types';
import type { RuleDetails, RulesRecord, RuleEntry } from '../types';
import { shallowEqual } from '../lib/shallowEqual';

export interface ModalEslintProps {
Expand Down
10 changes: 5 additions & 5 deletionspackages/website/src/components/editor/LoadedEditor.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
import React, { useMemo } from 'react';
import type Monaco from 'monaco-editor';
import { useEffect, useRef, useState } from 'react';
import type { WebLinter } from '@typescript-eslint/website-eslint';
import type { SandboxInstance } from './useSandboxServices';
import type { CommonEditorProps } from './types';
import type { WebLinter } from '../linter/WebLinter';

import { debounce } from '../lib/debounce';
import { lintCode, LintCodeAction } from './lintCode';
import { lintCode, LintCodeAction } from '../linter/lintCode';
import { createProvideCodeActions } from './createProvideCodeActions';

export interface LoadedEditorProps extends CommonEditorProps {
Expand DownExpand Up@@ -83,9 +83,9 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
);
}

onEsASTChange(fatalMessage ?? webLinter.getAst());
onTsASTChange(fatalMessage ?? webLinter.getTsAst());
onScopeChange(fatalMessage ?? webLinter.getScope());
onEsASTChange(fatalMessage ?? webLinter.storedAST ?? '');
onTsASTChange(fatalMessage ?? webLinter.storedTsAST ?? '');
onScopeChange(fatalMessage ?? webLinter.storedScope ?? '');
onSelect(sandboxInstance.editor.getPosition());
}, 500),
[code, jsx, sandboxInstance, rules, sourceType, tsConfig, webLinter],
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp