eslint-plugin-interface-method-style v1.1.5
eslint-plugin-interface-method-style
ESLint rule to enforce consistent method implementation styles between TypeScript interfaces and their implementations.
Table of Contents
Introduction
In large TypeScript codebases, maintaining consistency between interfaces and their implementations is crucial for code readability and maintainability. This ESLint plugin ensures that methods and properties defined in TypeScript interfaces or type aliases are implemented using the same syntax in classes and object literals.
Features
- 🎯 Method Style Consistency: Ensures consistent method and property styles.
- 🚀 Supports Classes and Object Literals: Works with classes and object literals.
- ✨ TypeScript Compatibility: Supports TypeScript interfaces and type aliases.
Installation
npm
npm install eslint-plugin-interface-method-style --save-devYarn
yarn add eslint-plugin-interface-method-style --devpnpm
pnpm add eslint-plugin-interface-method-style --save-devUsage
Add interface-method-style to your ESLint configuration.
Config (eslint.config.mjs)
import interfaceMethodStyle from "eslint-plugin-interface-method-style";
export default [
// ...
interfaceMethodStyle.configs.recommended,
];Legacy Config (.eslintrc.json)
Add interface-method-style to the plugins section of your configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": ["interface-method-style"]
}Then configure the rules you want to use under the rules section.
{
"rules": {
"interface-method-style/interface-method-style": "error"
}
}Rule Details
This rule enforces that the implementation of methods and properties matches their definitions in the interfaces or type aliases:
- Methods defined with
method(): voidmust be implemented as methods - Properties defined with
method: () => voidmust be implemented as arrow functions
✅ Correct
interface Foo {
method(): void;
property: () => void;
}
class Bar implements Foo {
method() {
console.log("method");
}
property = () => {
console.log("property");
};
}❌ Incorrect
interface Foo {
method(): void;
property: () => void;
}
class Bar implements Foo {
method = () => {
console.log("method");
};
property() {
console.log("property");
}
}License
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago