Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(website): add playground to website #4108

Merged
merged 50 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8d960ad
chore(website): migrate playground from #3147
armano2 Nov 8, 2021
c09021e
Merge branch 'master' into website-playground
armano2 Nov 8, 2021
09613a1
chore(website): playground compilation fix, not fully working
armano2 Nov 9, 2021
a121f03
docs: allow playground to be executed
armano2 Nov 11, 2021
5961541
docs: fix circular modules
armano2 Nov 11, 2021
bc4f486
Merge branch 'master' into website-playground
armano2 Nov 11, 2021
40c5e38
docs(website): regenerate vendors
armano2 Nov 11, 2021
6b70c80
Merge branch 'master' into website-playground
armano2 Nov 11, 2021
bf5870d
Merge remote-tracking branch 'origin/master' into website-playground
armano2 Nov 15, 2021
92a235a
Merge remote-tracking branch 'armano2/master' into website-playground
armano2 Nov 15, 2021
4339a46
fix: update playground
armano2 Nov 15, 2021
fc36401
fix: expose linter types from website-eslint
armano2 Nov 16, 2021
0f7439f
fix(website): add extended eslint config editor
armano2 Nov 18, 2021
fef660f
Merge remote-tracking branch 'origin/master' into website-playground
armano2 Nov 18, 2021
d5dc0c6
fix(website): enable default focus on search input
armano2 Nov 18, 2021
e58eefc
refactor(website): refactor codebase
armano2 Nov 18, 2021
d9c277e
refactor(website): mark all props as readonly
armano2 Nov 18, 2021
368b0bf
refactor(website): migrate config code to use reducers
armano2 Nov 18, 2021
9e5f387
refactor(website): ensure correct focus for textarea
armano2 Nov 18, 2021
80a5a3f
refactor(website): update useHashState
armano2 Nov 18, 2021
60d617c
refactor(website): add missing error handling
armano2 Nov 18, 2021
193dec5
refactor(website): add basic tsconfig edit
armano2 Nov 18, 2021
697d811
refactor(website): simplify components
armano2 Nov 18, 2021
0e1f198
refactor(website): add basic config validation
armano2 Nov 19, 2021
86af1b9
refactor(website): refactor config editors
armano2 Nov 19, 2021
d8bc68c
refactor(website): get all registered rules instead of only from esli…
armano2 Nov 19, 2021
b9c0fd2
fix: correct invalid header in modals
armano2 Nov 19, 2021
023400e
Merge remote-tracking branch 'origin/main' into website-playground
armano2 Nov 20, 2021
0af7777
chore(website): add actions to playground
armano2 Nov 20, 2021
a1a1114
chore(website): fix issue with isLoading
armano2 Nov 20, 2021
171087b
chore(website): final code cleanup
armano2 Nov 20, 2021
c549ca8
Merge remote-tracking branch 'origin/main' into website-playground
armano2 Nov 20, 2021
a3b4f40
chore(website): simplify code of editor
armano2 Nov 21, 2021
d636bb0
chore(website): use BrowserOnly component to load playground
armano2 Nov 21, 2021
c466baf
chore(website): apply first part of changes requested in code review
armano2 Nov 21, 2021
62d12c1
chore(website): refactor editor to use composite api
armano2 Nov 21, 2021
4aeee36
chore(website): improve playground position, and scrolling of options
armano2 Nov 21, 2021
5b13139
chore(website): correct issue with changing typescript version
armano2 Nov 22, 2021
30ff108
Merge branch 'main' into pr/armano2/4108
bradzacher Nov 24, 2021
ef239bf
docs(website): refactor ast viewer
armano2 Nov 26, 2021
0d5ca6c
Merge remote-tracking branch 'origin/main' into website-playground
armano2 Nov 26, 2021
dd3385d
chore(website): fix reverse hovering error
armano2 Nov 26, 2021
37414ab
chore(website): correct z-index of playground and allow hints to be seen
armano2 Nov 27, 2021
4f8702b
Merge remote-tracking branch 'origin/main' into website-playground
armano2 Nov 29, 2021
d0c2fb6
chore(website-eslint): add missing comments
armano2 Nov 29, 2021
3472b61
chore(website-eslint): correct some of linting errors
armano2 Nov 29, 2021
1996667
chore: disable spelling check for vendor
armano2 Nov 29, 2021
f9baefe
chore: xposed -> exposed
armano2 Nov 29, 2021
403fceb
fix: add missing dev deps for website-eslint
armano2 Nov 29, 2021
e66e0a0
fix: revert unnecessary changes and add missing command
armano2 Nov 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"IIFE",
"IIFEs",
"linebreaks",
"lzstring",
"necroing",
"nocheck",
"nullish",
Expand Down Expand Up @@ -96,6 +97,7 @@
"transpiled",
"transpiles",
"transpiling",
"tsvfs",
"tsconfigs",
"tsutils",
"typedef",
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CHANGELOG.md

packages/website/.docusaurus
packages/website/build
packages/website/src/vendor

# TODO - remove this once prettier supports TS4.1
packages/scope-manager/tests/fixtures/type-declaration/literal-type1.ts
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"url": "https://github.com/typescript-eslint/typescript-eslint/issues"
},
"scripts": {
"build": "npx nx prebuild @typescript-eslint/types && nx run-many --target=build --all --parallel",
"build": "npx nx prebuild @typescript-eslint/types && nx run-many --target=build --all --parallel --exclude website",
"check-clean-workspace-after-install": "git diff --quiet --exit-code",
"check-configs": "nx run-many --target=check-configs --all --parallel",
"check-docs": "nx run-many --target=check-docs --all --parallel",
Expand All @@ -33,6 +33,7 @@
"format": "prettier --write \"./**/*.{ts,tsx,js,jsx,json,md,css}\"",
"generate-contributors": "yarn ts-node --transpile-only ./tools/generate-contributors.ts && yarn all-contributors generate",
"generate-sponsors": "yarn ts-node --transpile-only ./tools/generate-sponsors.ts",
"generate-website-dts": "yarn ts-node --transpile-only ./tools/generate-website-dts.ts",
"lint-fix": "eslint . --ext .js,.ts --fix",
"lint-markdown-fix": "yarn lint-markdown --fix",
"lint-markdown": "markdownlint \"**/*.md\" --config=.markdownlint.json --ignore-path=.markdownlintignore",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-restricted-imports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TSESTree } from '@typescript-eslint/experimental-utils';
import {
import type {
ArrayOfStringOrObject,
ArrayOfStringOrObjectPatterns,
} from 'eslint/lib/rules/no-restricted-imports';
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/src/referencer/PatternVisitor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types';
import { VisitorBase, VisitorOptions } from './Visitor';
import { VisitorBase, VisitorOptions } from './VisitorBase';
armano2 marked this conversation as resolved.
Show resolved Hide resolved

type PatternVisitorCallback = (
pattern: TSESTree.Identifier,
Expand Down
27 changes: 27 additions & 0 deletions packages/website-eslint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@typescript-eslint/website-eslint",
"version": "5.3.1",
"private": true,
"description": "ESLint which works in browsers.",
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"main": "dist/index.js",
"files": [
"dist"
],
"scripts": {
"build": "rollup --config=rollup.config.js"
},
"dependencies": {
"eslint": "*"
},
"devDependencies": {
"eslint": "*",
"rollup": "^2.59.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/pluginutils": "^3.1.0"
}
}
armano2 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions packages/website-eslint/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"root": "packages/website-eslint",
"type": "library",
"implicitDependencies": []
}
94 changes: 94 additions & 0 deletions packages/website-eslint/rollup-plugin/replace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const path = require('path');
const Module = require('module');
const rollupPluginUtils = require('@rollup/pluginutils');
const MagicString = require('magic-string');

function toAbsolute(id) {
return id.startsWith('./') ? path.resolve(id) : require.resolve(id);
}

function log(opts, message, type = 'info') {
if (opts.verbose) {
console.log('rollup-plugin-replace > [' + type + ']', message);
}
}

function createMatcher(it) {
if (typeof it === 'function') {
return it;
} else {
return rollupPluginUtils.createFilter(it);
}
}

module.exports = (options = {}) => {
const aliasesCache = new Map();
const aliases = (options.alias || []).map(item => {
return {
match: item.match,
matcher: createMatcher(item.match),
target: item.target,
absoluteTarget: toAbsolute(item.target),
};
});
const replaces = (options.replace || []).map(item => {
return {
match: item.match,
test: item.test,
replace:
typeof item.replace === 'string' ? () => item.replace : item.replace,

matcher: createMatcher(item.match),
};
});

return {
name: 'rollup-plugin-replace',
resolveId(id, importerPath) {
const importeePath =
id.startsWith('./') || id.startsWith('../')
? Module.createRequire(importerPath).resolve(id)
: id;

let result = aliasesCache.get(importeePath);
if (result) {
return result;
}

result = aliases.find(item => item.matcher(importeePath));
if (result) {
aliasesCache.set(importeePath, result.absoluteTarget);
log(options, `${importeePath} as ${result.target}`, 'resolve');
return result.absoluteTarget;
}

return null;
},
transform(code, id) {
let hasReplacements = false;
let magicString = new MagicString(code);

replaces.forEach(item => {
if (item.matcher && !item.matcher(id)) {
return;
}

let match = item.test.exec(code);
let start, end;
while (match) {
hasReplacements = true;
start = match.index;
end = start + match[0].length;
magicString.overwrite(start, end, item.replace(match));
match = item.test.global ? item.test.exec(code) : null;
}
});

if (!hasReplacements) {
return;
}
log(options, id, 'replace');
return { code: magicString.toString() };
},
};
};
83 changes: 83 additions & 0 deletions packages/website-eslint/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
const replace = require('./rollup-plugin/replace');

module.exports = {
input: 'src/linter/linter.js',
output: {
format: 'module',
interop: 'auto',
freeze: false,
file: 'dist/index.js',
},
external: ['typescript'],
plugins: [
replace({
// verbose: true,
alias: [
{
match: [
/eslint\/lib\/(rule-tester|eslint|cli-engine|init)\//u,
/eslint\/lib\/cli\.js$/,
/experimental-utils\/dist\/eslint-utils\/RuleTester\.js$/,
/experimental-utils\/dist\/ts-eslint\/CLIEngine\.js$/,
/experimental-utils\/dist\/ts-eslint\/RuleTester\.js$/,
// 'typescript-estree/dist/create-program/createWatchProgram.js',
// 'typescript-estree/dist/create-program/createProjectProgram.js',
// 'typescript-estree/dist/create-program/createIsolatedProgram.js',
// 'eslint/lib/shared/ajv.js',
// 'eslint/lib/shared/runtime-info.js',
],
target: './src/mock/empty.js',
},
{
match: /^assert$/u,
target: './src/mock/assert.js',
},
{
match: /^path$/u,
target: './src/mock/path.js',
},
{
match: /^util$/u,
target: './src/mock/util.js',
},
],
replace: [
{
match: /eslint\/lib\/linter\/rules\.js$/u,
test: /require\(this\._rules\[ruleId\]\)/u,
replace: 'null',
},
{
test: /esquery\.parse\(/u,
replace: 'esquery.default.parse(',
},
{
test: /esquery\.matches\(/u,
replace: 'esquery.default.matches(',
},
{
test: /process\.env\.NODE_DEBUG/u,
replace: 'false',
},
{
test: /process\.env\.TIMING/u,
replace: 'false',
},
{
test: /process\.env\.IGNORE_TEST_WIN32/u,
replace: 'true',
},
],
}),
// nodePolyfills(),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
json({ preferConst: true }),
],
};
48 changes: 48 additions & 0 deletions packages/website-eslint/src/linter/CompilerHost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { getDefaultLibFileName } from 'typescript';
armano2 marked this conversation as resolved.
Show resolved Hide resolved

export class CompilerHost {
constructor(files, sourceFiles) {
this.files = files;
this.sourceFiles = sourceFiles;
}

fileExists(name) {
return !!this.files[name];
}

getCanonicalFileName(name) {
return name;
}

getCurrentDirectory() {
return '/';
}

getDirectories() {
return [];
}

getDefaultLibFileName(options) {
return '/' + getDefaultLibFileName(options);
}

getNewLine() {
return '\n';
}

useCaseSensitiveFileNames() {
return true;
}

writeFile() {
return null;
}

readFile(name) {
return this.files[name];
}

getSourceFile(name) {
return this.sourceFiles[name];
}
}
24 changes: 24 additions & 0 deletions packages/website-eslint/src/linter/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const extra = {
code: '',
comment: true,
comments: [],
createDefaultProgram: false,
debugLevel: new Set(),
errorOnTypeScriptSyntacticAndSemanticIssues: false,
errorOnUnknownASTType: false,
extraFileExtensions: [],
filePath: '',
jsx: false,
loc: true,
log: console.log,
preserveNodeMaps: true,
projects: [],
range: true,
strict: false,
tokens: [],
tsconfigRootDir: '/',
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: false,
singleRun: false,
programs: null,
moduleResolver: '',
};
44 changes: 44 additions & 0 deletions packages/website-eslint/src/linter/create-ast-program.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
createProgram,
createSourceFile,
ScriptTarget,
ScriptKind,
JsxEmit,
ModuleKind,
} from 'typescript';
import { CompilerHost } from './CompilerHost';

export function createASTProgram(code, parserOptions) {
const isJsx = !!parserOptions?.ecmaFeatures?.jsx;
const fileName = isJsx ? '/demo.tsx' : '/demo.ts';
const files = {
[fileName]: code,
};
const sourceFiles = {
[fileName]: createSourceFile(
fileName,
code,
ScriptTarget.Latest,
true,
isJsx ? ScriptKind.TSX : ScriptKind.TS,
),
};
const compilerHost = new CompilerHost(files, sourceFiles);
const compilerOptions = {
noResolve: true,
strict: true,
target: ScriptTarget.Latest,
jsx: isJsx ? JsxEmit.React : undefined,
module: ModuleKind.ES2015,
};
const program = createProgram(
Object.keys(files),
compilerOptions,
compilerHost,
);
const ast = program.getSourceFile(fileName);
return {
ast,
program,
};
}