1.1.5 • Published 7 months ago

eslint-plugin-interface-method-style v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

eslint-plugin-interface-method-style

ESLint rule to enforce consistent method implementation styles between TypeScript interfaces and their implementations.

npm npm GitHub FOSSA Status

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-dev

Yarn

yarn add eslint-plugin-interface-method-style --dev

pnpm

pnpm add eslint-plugin-interface-method-style --save-dev

Usage

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(): void must be implemented as methods
  • Properties defined with method: () => void must 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

FOSSA Status

1.1.5

7 months ago

1.1.5-beta.17

7 months ago

1.1.5-beta.16

7 months ago

1.1.5-beta.15

7 months ago

1.1.5-beta.14

7 months ago

1.1.5-beta.13

7 months ago

1.1.5-beta.12

7 months ago

1.1.5-beta.11

7 months ago

1.1.5-beta.10

7 months ago

1.1.5-beta.9

7 months ago

1.1.5-beta.8

7 months ago

1.1.5-beta.7

7 months ago

1.1.5-beta.6

7 months ago

1.1.5-beta.5

7 months ago

1.1.5-beta.4

7 months ago

1.1.5-beta.3

7 months ago

1.1.5-beta.2

7 months ago

1.1.5-beta.1

7 months ago

1.1.5-beta.0

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.1.0-beta.0

7 months ago