mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-25 04:36:23 +00:00
For each target, allow importing itself
This commit is contained in:
@@ -98,8 +98,7 @@
|
||||
{
|
||||
"target": "src/vs/base/common/**",
|
||||
"restrictions": [
|
||||
"vs/nls",
|
||||
"vs/base/common/**"
|
||||
"vs/nls"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -109,8 +108,7 @@
|
||||
"sinon",
|
||||
"sinon-test",
|
||||
"vs/nls",
|
||||
"vs/base/common/**",
|
||||
"vs/base/test/common/**"
|
||||
"vs/base/common/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -155,8 +153,7 @@
|
||||
"target": "src/vs/base/parts/*/common/**",
|
||||
"restrictions": [
|
||||
"vs/nls",
|
||||
"vs/base/common/**",
|
||||
"vs/base/parts/*/common/**"
|
||||
"vs/base/common/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -224,7 +221,6 @@
|
||||
"vs/nls",
|
||||
"vs/base/common/**",
|
||||
"vs/base/parts/*/common/**",
|
||||
"vs/platform/*/common/**",
|
||||
"tas-client-umd"
|
||||
]
|
||||
},
|
||||
@@ -238,8 +234,7 @@
|
||||
"vs/base/common/**",
|
||||
"vs/base/parts/*/common/**",
|
||||
"vs/base/test/common/**",
|
||||
"vs/platform/*/common/**",
|
||||
"vs/platform/*/test/common/**"
|
||||
"vs/platform/*/common/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -331,8 +326,7 @@
|
||||
"restrictions": [
|
||||
"vs/nls",
|
||||
"vs/base/common/**",
|
||||
"vs/platform/*/common/**",
|
||||
"vs/editor/common/**"
|
||||
"vs/platform/*/common/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -346,8 +340,7 @@
|
||||
"vs/base/test/common/**",
|
||||
"vs/platform/*/common/**",
|
||||
"vs/platform/*/test/common/**",
|
||||
"vs/editor/common/**",
|
||||
"vs/editor/test/common/**"
|
||||
"vs/editor/common/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -380,8 +373,7 @@
|
||||
"vs/nls",
|
||||
"vs/base/common/**",
|
||||
"vs/platform/*/common/**",
|
||||
"vs/editor/common/**",
|
||||
"vs/editor/standalone/common/**"
|
||||
"vs/editor/common/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -452,8 +444,7 @@
|
||||
"vs/base/parts/*/{common,browser}/**",
|
||||
"vs/platform/{common,browser}/**",
|
||||
"vs/platform/*/{common,browser}/**",
|
||||
"vs/editor/{common,browser}/**",
|
||||
"vs/editor/contrib/**"
|
||||
"vs/editor/{common,browser}/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -487,7 +478,6 @@
|
||||
"vs/platform/*/common/**",
|
||||
"vs/editor/common/**",
|
||||
"vs/editor/contrib/*/common/**",
|
||||
"vs/workbench/common/**",
|
||||
"vs/workbench/services/*/common/**",
|
||||
"assert"
|
||||
]
|
||||
@@ -517,7 +507,6 @@
|
||||
"vs/platform/*/common/**",
|
||||
"vs/editor/common/**",
|
||||
"vs/editor/contrib/*/common/**",
|
||||
"vs/workbench/api/common/**",
|
||||
"vs/workbench/common/**",
|
||||
"vs/workbench/services/*/common/**",
|
||||
"vs/workbench/contrib/*/common/**"
|
||||
@@ -623,7 +612,6 @@
|
||||
"vs/editor/common/**",
|
||||
"vs/workbench/workbench.web.api",
|
||||
"vs/workbench/common/**",
|
||||
"vs/workbench/services/**/common/**",
|
||||
"vs/workbench/api/**/common/**",
|
||||
"vscode-textmate",
|
||||
"vscode-oniguruma",
|
||||
@@ -795,8 +783,7 @@
|
||||
"vs/editor/**",
|
||||
"vs/workbench/common/**",
|
||||
"vs/workbench/api/common/**",
|
||||
"vs/workbench/services/**/common/**",
|
||||
"vs/workbench/contrib/**/common/**"
|
||||
"vs/workbench/services/**/common/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -943,7 +930,6 @@
|
||||
"vs/base/parts/**/{common,node}/**",
|
||||
"vs/platform/**/{common,node}/**",
|
||||
"vs/workbench/**/{common,node}/**",
|
||||
"vs/server/**",
|
||||
"@vscode/*",
|
||||
"@parcel/*",
|
||||
"*" // node modules
|
||||
|
||||
@@ -25,28 +25,52 @@ module.exports = new class {
|
||||
url: 'https://github.com/microsoft/vscode/wiki/Source-Code-Organization'
|
||||
}
|
||||
};
|
||||
this._optionsCache = new WeakMap();
|
||||
}
|
||||
create(context) {
|
||||
const configs = this._processOptions(context.options);
|
||||
const options = context.options;
|
||||
const { configs, warnings } = this._processOptions(options);
|
||||
const relativeFilename = getRelativeFilename(context);
|
||||
if (warnings.length > 0) {
|
||||
// configuration warnings
|
||||
context.report({
|
||||
loc: { line: 1, column: 0 },
|
||||
message: warnings.join('\n')
|
||||
});
|
||||
return {};
|
||||
}
|
||||
for (const config of configs) {
|
||||
if (minimatch(relativeFilename, config.target)) {
|
||||
return (0, utils_1.createImportRuleListener)((node, value) => this._checkImport(context, config, node, value));
|
||||
}
|
||||
}
|
||||
context.report({
|
||||
loc: { line: 1, column: 1 },
|
||||
loc: { line: 1, column: 0 },
|
||||
messageId: 'badFilename'
|
||||
});
|
||||
return {};
|
||||
}
|
||||
_processOptions(options) {
|
||||
const result = [];
|
||||
if (this._optionsCache.has(options)) {
|
||||
return this._optionsCache.get(options);
|
||||
}
|
||||
const configs = [];
|
||||
const warnings = [];
|
||||
for (const option of options) {
|
||||
const target = option.target;
|
||||
const restrictions = (typeof option.restrictions === 'string' ? [option.restrictions] : option.restrictions);
|
||||
result.push({ target, restrictions });
|
||||
const restrictions = (typeof option.restrictions === 'string' ? [option.restrictions] : option.restrictions.slice(0));
|
||||
if (/^src\/vs\/.*\/\*\*/.test(target)) {
|
||||
const amdTarget = target.substring('src/'.length);
|
||||
// Allow importing itself
|
||||
if (restrictions.includes(amdTarget)) {
|
||||
warnings.push(`target ${target}: '${amdTarget}' is automatically included in restrictions.`);
|
||||
}
|
||||
restrictions.push(amdTarget);
|
||||
}
|
||||
configs.push({ target, restrictions });
|
||||
}
|
||||
const result = { configs, warnings };
|
||||
this._optionsCache.set(options, result);
|
||||
return result;
|
||||
}
|
||||
_checkImport(context, config, node, importPath) {
|
||||
|
||||
@@ -34,10 +34,19 @@ export = new class implements eslint.Rule.RuleModule {
|
||||
};
|
||||
|
||||
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
|
||||
|
||||
const configs = this._processOptions(<RawImportPatternsConfig[]>context.options);
|
||||
const options = <RawImportPatternsConfig[]>context.options;
|
||||
const { configs, warnings } = this._processOptions(options);
|
||||
const relativeFilename = getRelativeFilename(context);
|
||||
|
||||
if (warnings.length > 0) {
|
||||
// configuration warnings
|
||||
context.report({
|
||||
loc: { line: 1, column: 0 },
|
||||
message: warnings.join('\n')
|
||||
});
|
||||
return {};
|
||||
}
|
||||
|
||||
for (const config of configs) {
|
||||
if (minimatch(relativeFilename, config.target)) {
|
||||
return createImportRuleListener((node, value) => this._checkImport(context, config, node, value));
|
||||
@@ -45,20 +54,36 @@ export = new class implements eslint.Rule.RuleModule {
|
||||
}
|
||||
|
||||
context.report({
|
||||
loc: { line: 1, column: 1 },
|
||||
loc: { line: 1, column: 0 },
|
||||
messageId: 'badFilename'
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
private _processOptions(options: RawImportPatternsConfig[]): ImportPatternsConfig[] {
|
||||
const result: ImportPatternsConfig[] = [];
|
||||
private _optionsCache = new WeakMap<RawImportPatternsConfig[], { configs: ImportPatternsConfig[]; warnings: string[]; }>();
|
||||
|
||||
private _processOptions(options: RawImportPatternsConfig[]): { configs: ImportPatternsConfig[]; warnings: string[]; } {
|
||||
if (this._optionsCache.has(options)) {
|
||||
return this._optionsCache.get(options)!;
|
||||
}
|
||||
const configs: ImportPatternsConfig[] = [];
|
||||
const warnings: string[] = [];
|
||||
for (const option of options) {
|
||||
const target = option.target;
|
||||
const restrictions = (typeof option.restrictions === 'string' ? [option.restrictions] : option.restrictions);
|
||||
result.push({ target, restrictions });
|
||||
const restrictions = (typeof option.restrictions === 'string' ? [option.restrictions] : option.restrictions.slice(0));
|
||||
if (/^src\/vs\/.*\/\*\*/.test(target)) {
|
||||
const amdTarget = target.substring('src/'.length);
|
||||
// Allow importing itself
|
||||
if (restrictions.includes(amdTarget)) {
|
||||
warnings.push(`target ${target}: '${amdTarget}' is automatically included in restrictions.`);
|
||||
}
|
||||
restrictions.push(amdTarget);
|
||||
}
|
||||
configs.push({ target, restrictions });
|
||||
}
|
||||
const result = { configs, warnings };
|
||||
this._optionsCache.set(options, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user