Skip to content

Commit

Permalink
feat(eslint-config): Update constructor access modifier eslint rule t…
Browse files Browse the repository at this point in the history
…o require explicit modifiers (#13134)

Updates rule to match discussion outcome in [this
discussion](#9502 (comment)).

Rule documentation:
https://typescript-eslint.io/rules/explicit-member-accessibility/

Also fixes violations in packages using the `strict` config

### Breaking Change

Note that this is a breaking change with respect to the above rule. We
are changing error-level enforcement of the policy to the opposite rule,
so code changes will be required. This PR pre-fixes the violations
existing at this point in time, but any changes between now and when the
new package is published and adopted will need to be fixed.
  • Loading branch information
Josmithr authored Dec 5, 2022
1 parent 1b00075 commit faa9111
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 16 deletions.
15 changes: 15 additions & 0 deletions azure/packages/azure-client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ module.exports = {
// Ensure jsdoc/tsdoc comments contain a main description component
// (disallows empty comments / only tags).
"jsdoc/require-description": ["error", { checkConstructors: false }],

// TODO: remove once dependency on base config has been updated.
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "explicit",
methods: "explicit",
properties: "explicit",
parameterProperties: "explicit",
},
},
],
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion azure/packages/azure-client/src/AzureClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class AzureClient {
* Creates a new client instance using configuration parameters.
* @param props - Properties for initializing a new AzureClient instance
*/
constructor(private readonly props: AzureClientProps) {
public constructor(private readonly props: AzureClientProps) {
// remove trailing slash from URL if any
props.connection.endpoint = props.connection.endpoint.replace(/\/$/, "");
this.urlResolver = new AzureUrlResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AzureFunctionTokenProvider implements ITokenProvider {
* @param azFunctionUrl - URL to Azure Function endpoint
* @param user - User object
*/
constructor(
public constructor(
private readonly azFunctionUrl: string,
private readonly user?: Pick<AzureMember, "userId" | "userName" | "additionalDetails">,
) {}
Expand Down
2 changes: 1 addition & 1 deletion azure/packages/azure-client/src/AzureUrlResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
* providers that fulfill the {@link @fluidframework/routerlicious-driver#ITokenProvider} interface.
*/
export class AzureUrlResolver implements IUrlResolver {
constructor() {}
public constructor() {}

public async resolve(request: IRequest): Promise<IFluidResolvedUrl> {
const { ordererUrl, storageUrl, tenantId, containerId } = decodeAzureUrl(request.url);
Expand Down
15 changes: 15 additions & 0 deletions azure/packages/azure-local-service/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ module.exports = {
// Ensure jsdoc/tsdoc comments contain a main description component
// (disallows empty comments / only tags).
"jsdoc/require-description": ["error", { checkConstructors: false }],

// TODO: remove once dependency on base config has been updated.
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "explicit",
methods: "explicit",
properties: "explicit",
parameterProperties: "explicit",
},
},
],
},
overrides: [
{
Expand Down
15 changes: 15 additions & 0 deletions azure/packages/azure-service-utils/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ module.exports = {
// Ensure jsdoc/tsdoc comments contain a main description component
// (disallows empty comments / only tags).
"jsdoc/require-description": ["error", { checkConstructors: false }],

// TODO: remove once dependency on base config has been updated.
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "explicit",
methods: "explicit",
properties: "explicit",
parameterProperties: "explicit",
},
},
],
},
overrides: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"accessibility": "explicit",
"overrides": {
"accessors": "explicit",
"constructors": "no-public",
"constructors": "explicit",
"methods": "explicit",
"parameterProperties": "explicit",
"properties": "explicit"
Expand Down
2 changes: 1 addition & 1 deletion common/build/eslint-config-fluid/strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "no-public",
constructors: "explicit",
methods: "explicit",
properties: "explicit",
parameterProperties: "explicit",
Expand Down
17 changes: 16 additions & 1 deletion examples/hosts/app-integration/external-data/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,20 @@ module.exports = {
"prettier"
),
],
rules: {},
rules: {
// TODO: remove once dependency on base config has been updated.
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "explicit",
methods: "explicit",
properties: "explicit",
parameterProperties: "explicit",
},
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface IExternalDataSourceEvents extends IEvent {
* on the server-side bot approach. But using localStorage is probably good enough for the broadcast signal portion.
*/
export class ExternalDataSource extends TypedEventEmitter<IExternalDataSourceEvents> {
constructor() {
public constructor() {
super();
if (window.localStorage.getItem(localStorageKey) === null) {
this.debugResetData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { IAppModel, IAppModelEvents, ITaskList } from "../modelInterfaces";
* responsibilities and functionality.
*/
export class AppModel extends TypedEventEmitter<IAppModelEvents> implements IAppModel {
constructor(public readonly taskList: ITaskList, container: IContainer) {
public constructor(public readonly taskList: ITaskList, container: IContainer) {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const SignalType = {
* {@inheritDoc ModelContainerRuntimeFactory}
*/
export class TaskListContainerRuntimeFactory extends ModelContainerRuntimeFactory<IAppModel> {
constructor() {
public constructor() {
super(
new Map([TaskListInstantiationFactory.registryEntry]), // registryEntries
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Task extends TypedEventEmitter<ITaskEvents> implements ITask {
public set priority(newValue: number) {
this._priority.set(newValue);
}
constructor(
public constructor(
private readonly _id: string,
private readonly _name: SharedString,
private readonly _priority: ISharedCell<number>
Expand Down
17 changes: 16 additions & 1 deletion packages/dds/quorum/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,20 @@ module.exports = {
],
"parserOptions": {
"project": ["./tsconfig.json", "./src/test/tsconfig.json"]
},
}, "rules": {
// TODO: remove once dependency on base config has been updated.
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "explicit",
methods: "explicit",
properties: "explicit",
parameterProperties: "explicit",
},
},
],
}
}
1 change: 0 additions & 1 deletion packages/dds/quorum/src/quorum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export class Quorum<T = unknown> extends SharedObject<IQuorumEvents> implements
* @param runtime - data store runtime the quorum belongs to
* @param id - optional name of the quorum
*/
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
public constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {
super(id, runtime, attributes, "fluid_quorum_");

Expand Down
15 changes: 15 additions & 0 deletions tools/api-markdown-documenter/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,20 @@ module.exports = {

// This package is exclusively used in a Node.js context
"import/no-nodejs-modules": "off",

// TODO: remove once dependency on base config has been updated.
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "explicit",
methods: "explicit",
properties: "explicit",
parameterProperties: "explicit",
},
},
],
},
};
5 changes: 4 additions & 1 deletion tools/api-markdown-documenter/src/MarkdownEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export class MarkdownEmitter extends BaseMarkdownEmitter {
* @param apiModel - See {@link MarkdownEmitter.apiModel}.
* @param generateFrontMatter - See {@link MarkdownEmitter.generateFrontMatter}.
*/
constructor(apiModel: ApiModel, generateFrontMatter?: (contextApiItem: ApiItem) => string) {
public constructor(
apiModel: ApiModel,
generateFrontMatter?: (contextApiItem: ApiItem) => string,
) {
super();
this.apiModel = apiModel;
this.generateFrontMatter = generateFrontMatter;
Expand Down
2 changes: 1 addition & 1 deletion tools/api-markdown-documenter/src/doc-nodes/DocAlert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class DocAlert extends DocNode {
*/
public readonly content: DocNode;

constructor(parameters: IDocAlertParameters, content: DocNode) {
public constructor(parameters: IDocAlertParameters, content: DocNode) {
super(parameters);

this.type = parameters.type;
Expand Down
2 changes: 1 addition & 1 deletion tools/api-markdown-documenter/src/doc-nodes/DocHeading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DocHeading extends DocNode {
*/
public readonly id?: string;

constructor(parameters: IDocHeadingParameters) {
public constructor(parameters: IDocHeadingParameters) {
super(parameters);

this.title = parameters.title;
Expand Down
2 changes: 1 addition & 1 deletion tools/api-markdown-documenter/src/doc-nodes/DocList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class DocList extends DocNodeContainer {
*/
public readonly listKind: ListKind;

constructor(parameters: IDocListParameters, childNodes?: readonly DocNode[]) {
public constructor(parameters: IDocListParameters, childNodes?: readonly DocNode[]) {
super(parameters, childNodes);

this.listKind = parameters.listKind ?? ListKind.Unordered;
Expand Down

0 comments on commit faa9111

Please sign in to comment.