Skip to content

Commit

Permalink
Merge branch 'main' into alexr00/sufficient-dog
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 committed Sep 30, 2024
2 parents ae98588 + fd58e9e commit 091e358
Show file tree
Hide file tree
Showing 289 changed files with 5,526 additions and 10,958 deletions.
7 changes: 0 additions & 7 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
**/src/vs/*/**/*.d.ts
**/src/vs/base/test/common/filters.perf.data.js
**/src/vs/loader.js
**/src2/**/dompurify.js
**/src2/**/marked.js
**/src2/**/semver.js
**/src2/typings/**/*.d.ts
**/src2/vs/*/**/*.d.ts
**/src2/vs/base/test/common/filters.perf.data.js
**/src2/vs/loader.js
**/test/unit/assert.js
**/test/unit/assert-esm.js
**/test/automation/out/**
Expand Down
70 changes: 70 additions & 0 deletions .eslintplugin/code-limited-top-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as eslint from 'eslint';
import { dirname, relative } from 'path';
import minimatch from 'minimatch';

export = new class implements eslint.Rule.RuleModule {

readonly meta: eslint.Rule.RuleMetaData = {
messages: {
layerbreaker: 'You are only allowed to define limited top level functions.'
},
schema: {
type: "array",
items: {
type: "object",
additionalProperties: {
type: "array",
items: {
type: "string"
}
}
}
}
};

create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
let fileRelativePath = relative(dirname(__dirname), context.getFilename());
if (!fileRelativePath.endsWith('/')) {
fileRelativePath += '/';
}
const ruleArgs = <Record<string, string[]>>context.options[0];

const matchingKey = Object.keys(ruleArgs).find(key => fileRelativePath.startsWith(key) || minimatch(fileRelativePath, key));
if (!matchingKey) {
// nothing
return {};
}

const restrictedFunctions = ruleArgs[matchingKey];

return {
FunctionDeclaration: (node: any) => {
const isTopLevel = node.parent.type === 'Program';
const functionName = node.id.name;
if (isTopLevel && !restrictedFunctions.includes(node.id.name)) {
context.report({
node,
message: `Top-level function '${functionName}' is restricted in this file. Allowed functions are: ${restrictedFunctions.join(', ')}.`
});
}
},
ExportNamedDeclaration(node: any) {
if (node.declaration && node.declaration.type === 'FunctionDeclaration') {
const functionName = node.declaration.id.name;
const isTopLevel = node.parent.type === 'Program';
if (isTopLevel && !restrictedFunctions.includes(node.declaration.id.name)) {
context.report({
node,
message: `Top-level function '${functionName}' is restricted in this file. Allowed functions are: ${restrictedFunctions.join(', ')}.`
});
}
}
}
}
}
};
32 changes: 11 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,7 @@
// - browser
// - electron-sandbox
"when": "hasBrowser",
"allow": [
"vs/css!./**/*"
]
"allow": []
},
{
// imports that are allowed in all files of layers:
Expand Down Expand Up @@ -758,7 +756,6 @@
// imports that are allowed in all /test/ files
"when": "test",
"allow": [
"vs/css.build",
"vs/css.build.js",
"assert",
"sinon",
Expand Down Expand Up @@ -1008,18 +1005,10 @@
"vs/editor/~",
"vs/editor/contrib/*/~",
"vs/code/~",
{
"when": "hasBrowser",
"pattern": "vs/workbench/workbench.web.main"
},
{
"when": "hasBrowser",
"pattern": "vs/workbench/workbench.web.main.js"
},
{
"when": "hasBrowser",
"pattern": "vs/workbench/workbench.web.main.internal"
},
{
"when": "hasBrowser",
"pattern": "vs/workbench/workbench.web.main.internal.js"
Expand Down Expand Up @@ -1070,13 +1059,11 @@
"vs/platform/*/~",
"vs/editor/~",
"vs/editor/contrib/*/~",
"vs/editor/editor.all",
"vs/editor/editor.all.js",
"vs/workbench/~",
"vs/workbench/api/~",
"vs/workbench/services/*/~",
"vs/workbench/contrib/*/~",
"vs/workbench/contrib/terminal/terminal.all",
"vs/workbench/contrib/terminal/terminal.all.js"
]
},
Expand All @@ -1089,13 +1076,11 @@
"vs/platform/*/~",
"vs/editor/~",
"vs/editor/contrib/*/~",
"vs/editor/editor.all",
"vs/editor/editor.all.js",
"vs/workbench/~",
"vs/workbench/api/~",
"vs/workbench/services/*/~",
"vs/workbench/contrib/*/~",
"vs/workbench/workbench.common.main",
"vs/workbench/workbench.common.main.js"
]
},
Expand All @@ -1108,13 +1093,11 @@
"vs/platform/*/~",
"vs/editor/~",
"vs/editor/contrib/*/~",
"vs/editor/editor.all",
"vs/editor/editor.all.js",
"vs/workbench/~",
"vs/workbench/api/~",
"vs/workbench/services/*/~",
"vs/workbench/contrib/*/~",
"vs/workbench/workbench.common.main",
"vs/workbench/workbench.common.main.js"
]
},
Expand All @@ -1127,13 +1110,11 @@
"vs/platform/*/~",
"vs/editor/~",
"vs/editor/contrib/*/~",
"vs/editor/editor.all",
"vs/editor/editor.all.js",
"vs/workbench/~",
"vs/workbench/api/~",
"vs/workbench/services/*/~",
"vs/workbench/contrib/*/~",
"vs/workbench/workbench.common.main",
"vs/workbench/workbench.common.main.js"
]
},
Expand All @@ -1152,7 +1133,7 @@
"restrictions": []
},
{
"target": "src/{bootstrap-amd.js,bootstrap-fork.js,bootstrap-node.js,bootstrap-window.js,cli.js,main.js,server-cli.js,server-main.js,bootstrap-cli.js,bootstrap-server.js}",
"target": "src/{bootstrap-cli.ts,bootstrap-esm.ts,bootstrap-fork.ts,bootstrap-node.ts,bootstrap-import.ts,bootstrap-meta.ts,bootstrap-window.ts,cli.ts,main.ts,server-cli.ts,server-main.ts,bootstrap-server.ts}",
"restrictions": []
}
]
Expand Down Expand Up @@ -1222,6 +1203,15 @@
"**/*"
]
}
],
"local/code-limited-top-functions": [
"error",
{
"src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts": [
"webviewPreloads",
"preloadsScriptStr"
]
}
]
}
}
Expand Down
6 changes: 2 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"**/.DS_Store": true,
".vscode-test": true,
"cli/target": true,
"build/**/*.js.map": true,
"build/**/*.js": {
"when": "$(basename).ts"
}
Expand Down Expand Up @@ -41,8 +42,6 @@
"**/yarn.lock": true,
"**/package-lock.json": true,
"**/Cargo.lock": true,
"src/vs/workbench/workbench.web.main.css": true,
"src/vs/workbench/workbench.desktop.main.css": true,
"build/**/*.js": true,
"out/**": true,
"out-build/**": true,
Expand All @@ -52,8 +51,7 @@
"extensions/**/out/**": true,
"test/smoke/out/**": true,
"test/automation/out/**": true,
"test/integration/browser/out/**": true,
"src2/**": true,
"test/integration/browser/out/**": true
},
"files.readonlyExclude": {
"build/builtin/*.js": true,
Expand Down
18 changes: 0 additions & 18 deletions .vscode/shared.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,5 @@
"private readonly _onDid$1 = new Emitter<$2>();",
"readonly onDid$1: Event<$2> = this._onDid$1.event;"
],
},
"esm-comment": {
"scope": "typescript,javascript",
"prefix": "esm-comment",
"body": [
"// ESM-comment-begin",
"$SELECTION$0",
"// ESM-comment-end",
]
},
"esm-uncomment": {
"scope": "typescript,javascript",
"prefix": "esm-uncomment",
"body": [
"// ESM-uncomment-begin",
"// $SELECTION$0",
"// ESM-uncomment-end",
]
}
}
Loading

0 comments on commit 091e358

Please sign in to comment.