mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Start eslint 9 migration
For #230339 Starts migrating to eslint 9. Everything runs but it produces a number of errors
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { TSESTree } from '@typescript-eslint/utils';
|
||||
|
||||
/**
|
||||
* Enforces that all parameter properties have an explicit access modifier (public, protected, private).
|
||||
*
|
||||
* This catches a common bug where a service is accidentally made public by simply writing: `readonly prop: Foo`
|
||||
*/
|
||||
export = new class implements eslint.Rule.RuleModule {
|
||||
|
||||
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
|
||||
function check(inNode: any) {
|
||||
const node: TSESTree.TSParameterProperty = inNode;
|
||||
|
||||
// For now, only apply to injected services
|
||||
const firstDecorator = node.decorators?.at(0);
|
||||
if (
|
||||
firstDecorator?.expression.type !== 'Identifier'
|
||||
|| !firstDecorator.expression.name.endsWith('Service')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node.accessibility) {
|
||||
context.report({
|
||||
node: inNode,
|
||||
message: 'Parameter properties must have an explicit access modifier.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
['TSParameterProperty']: check,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user