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 all 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
3 changes: 3 additions & 0 deletions .cspell.json
Expand Up @@ -15,6 +15,7 @@
"**/node_modules/**",
"packages/website/.docusaurus/**",
"packages/website/build/**",
"packages/website/src/vendor/**",
"yarn.lock"
],
"dictionaries": [
Expand Down Expand Up @@ -71,6 +72,7 @@
"IIFEs",
"linebreaks",
"markdownlint",
"lzstring",
"necroing",
"nocheck",
"nullish",
Expand Down Expand Up @@ -99,6 +101,7 @@
"transpiled",
"transpiles",
"transpiling",
"tsvfs",
"tsconfigs",
"tsutils",
"typedef",
Expand Down
4 changes: 4 additions & 0 deletions .eslintignore
Expand Up @@ -6,11 +6,15 @@ fixtures
shared-fixtures
coverage
__snapshots__
.docusaurus
build

packages/eslint-plugin-tslint/tests

packages/website/**/*.js
packages/website/**/*.d.ts
packages/website-eslint/**/*.js
packages/website-eslint/**/*.d.ts

# Files copied as part of the build
packages/types/src/ast-spec.ts
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -205,7 +205,7 @@ module.exports = {
'jest/no-deprecated-functions': 'error',
},
},
// test utility scripts
// test utility scripts and website js files
{
files: ['tests/**/*.js'],
rules: {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@ yarn-error.log*
packages/website/.docusaurus
packages/website/.cache-loader
packages/website/build
packages/website/static/sandbox

# Runtime data
pids
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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,.jsx,.ts,.tsx --fix",
"lint-markdown-fix": "yarn lint-markdown --fix",
"lint-markdown": "markdownlint \"**/*.md\" --config=.markdownlint.json --ignore-path=.markdownlintignore",
Expand Down Expand Up @@ -60,7 +61,6 @@
"@babel/types": "^7.16.0",
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"@commitlint/config-lerna-scopes": "^15.0.0",
"@nrwl/cli": "13.0.2",
"@nrwl/nx-cloud": "12.5.1",
"@nrwl/tao": "13.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/util/getWrappingFixer.ts
@@ -1,10 +1,10 @@
import {
AST_NODE_TYPES,
TSESLint,
ASTUtils,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { SourceCode } from '@typescript-eslint/experimental-utils/src/ts-eslint';
import * as util from '../util';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i missed this in #4140


interface WrappingFixerParams {
/** Source code. */
Expand Down Expand Up @@ -57,7 +57,7 @@ export function getWrappingFixer(
if (isWeakPrecedenceParent(node)) {
// we wrapped the node in some expression which very likely has a different precedence than original wrapped node
// let's wrap the whole expression in parens just in case
if (!util.isParenthesized(node, sourceCode)) {
if (!ASTUtils.isParenthesized(node, sourceCode)) {
code = `(${code})`;
}
}
Expand Down
36 changes: 36 additions & 0 deletions packages/website-eslint/package.json
@@ -0,0 +1,36 @@
{
"name": "@typescript-eslint/website-eslint",
"version": "5.4.0",
"private": true,
"description": "ESLint which works in browsers.",
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"types": "types/index.d.ts",
"main": "dist/index.js",
"files": [
"dist"
],
"scripts": {
"build": "rollup --config=rollup.config.js",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "^5.4.0",
"@typescript-eslint/types": "^5.4.0"
},
"devDependencies": {
"eslint": "*",
"rollup": "^2.59.0",
"semver": "^7.3.5",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/pluginutils": "^3.1.0",
"@typescript-eslint/eslint-plugin": "5.4.0",
"@typescript-eslint/parser": "5.4.0",
"@typescript-eslint/scope-manager": "5.4.0",
"@typescript-eslint/typescript-estree": "5.4.0",
"@typescript-eslint/visitor-keys": "5.4.0"
}
}
armano2 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions packages/website-eslint/project.json
@@ -0,0 +1,5 @@
{
"root": "packages/website-eslint",
"type": "library",
"implicitDependencies": []
}
94 changes: 94 additions & 0 deletions packages/website-eslint/rollup-plugin/replace.js
@@ -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() };
},
};
};
103 changes: 103 additions & 0 deletions packages/website-eslint/rollup.config.js
@@ -0,0 +1,103 @@
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: 'amd',
interop: 'auto',
freeze: false,
file: 'dist/index.js',
},
external: ['vs/language/typescript/tsWorker'],
plugins: [
replace({
// verbose: true,
alias: [
{
// those files should be omitted, we do not want them to be exposed to web
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/,
/experimental-utils\/dist\/ts-eslint\/ESLint\.js/,
// 'eslint/lib/shared/ajv.js',
// 'eslint/lib/shared/runtime-info.js',
],
target: './src/mock/empty.js',
},
{
// use window.ts instead of bundling typescript
match: /typescript$/u,
target: './src/mock/typescript.js',
},
{
// assert for web
match: /^assert$/u,
target: './src/mock/assert.js',
},
{
// path for web
match: /^path$/u,
target: './src/mock/path.js',
},
{
// util for web
match: /^util$/u,
target: './src/mock/util.js',
},
{
// semver simplified, solve issue with circular dependencies
match: /semver$/u,
target: './src/mock/semver.js',
},
],
replace: [
{
// we do not want dynamic imports
match: /eslint\/lib\/linter\/rules\.js$/u,
test: /require\(this\._rules\[ruleId\]\)/u,
replace: 'null',
},
{
// esquery has both browser and node versions, we are bundling browser version that has different export
test: /esquery\.parse\(/u,
replace: 'esquery.default.parse(',
},
{
// esquery has both browser and node versions, we are bundling browser version that has different export
test: /esquery\.matches\(/u,
replace: 'esquery.default.matches(',
},
{
// replace all process.env.NODE_DEBUG with false
test: /process\.env\.NODE_DEBUG/u,
replace: 'false',
},
{
// replace all process.env.TIMING with false
test: /process\.env\.TIMING/u,
replace: 'false',
},
{
// replace all process.env.IGNORE_TEST_WIN32 with true
test: /process\.env\.IGNORE_TEST_WIN32/u,
replace: 'true',
},
],
}),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
json({ preferConst: true }),
],
};
48 changes: 48 additions & 0 deletions packages/website-eslint/src/linter/CompilerHost.js
@@ -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];
}
}