Skip to content

Commit

Permalink
feat(eslint-plugin): [lines-around-comment] add extension rule (#5327)
Browse files Browse the repository at this point in the history
* replicate eslint rule and add base test case

* port the eslint lines-around-comment

* check for comment in interface and allow options

* check for comment in type literals and allow options

* add lines-around-comment in index

* add lines-around-comment in all config

* add lines-around-comment doc

* delegate non-TS check to the base rule

* fix lint errors

* fix doc lint errors

* address comments

* address jsdoc comments

* proper comment language

* Update packages/eslint-plugin/src/rules/lines-around-comment.ts

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>

* remove irrevalant lines and improve test cov

* skip more cases

* add enum and module tests

* implement enum and module

* improve coverage

* remove ESilnt base rule test casese

* improve coverage

---------

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
  • Loading branch information
3 people committed Mar 13, 2023
1 parent d73d7d3 commit d55211c
Show file tree
Hide file tree
Showing 7 changed files with 1,593 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/eslint-plugin/docs/rules/lines-around-comment.md
@@ -0,0 +1,41 @@
---
description: 'Require empty lines around comments.'
---

> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/lines-around-comment** for documentation.
## Rule Details

This rule extends the base [`eslint/lines-around-comment`](https://eslint.org/docs/rules/lines-around-comment) rule.
It adds support for TypeScript syntax.

See the [ESLint documentation](https://eslint.org/docs/rules/lines-around-comment) for more details on the `comma-dangle` rule.

## Rule Changes

```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"lines-around-comment": "off",
"@typescript-eslint/lines-around-comment": ["error"]
}
```

In addition to the options supported by the `lines-around-comment` rule in ESLint core, the rule adds the following options:

## Options

- `allowInterfaceStart: true` doesn't require a blank line after the interface body block start
- `allowInterfaceEnd: true` doesn't require a blank line before the interface body block end
- `allowTypeStart: true` doesn't require a blank line after the type literal block start
- `allowTypeEnd: true` doesn't require a blank line after the type literal block end

[See the other options allowed](https://eslint.org/docs/rules/comma-dangle#options)

<sup>

Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/lines-around-comment.md)

</sup>
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/configs/all.ts
Expand Up @@ -43,6 +43,8 @@ export = {
'@typescript-eslint/key-spacing': 'error',
'keyword-spacing': 'off',
'@typescript-eslint/keyword-spacing': 'error',
'lines-around-comment': 'off',
'@typescript-eslint/lines-around-comment': 'error',
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': 'error',
'@typescript-eslint/member-delimiter-style': 'error',
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/index.ts
Expand Up @@ -25,6 +25,7 @@ import indent from './indent';
import initDeclarations from './init-declarations';
import keySpacing from './key-spacing';
import keywordSpacing from './keyword-spacing';
import linesAroundComment from './lines-around-comment';
import linesBetweenClassMembers from './lines-between-class-members';
import memberDelimiterStyle from './member-delimiter-style';
import memberOrdering from './member-ordering';
Expand Down Expand Up @@ -160,6 +161,7 @@ export default {
'init-declarations': initDeclarations,
'key-spacing': keySpacing,
'keyword-spacing': keywordSpacing,
'lines-around-comment': linesAroundComment,
'lines-between-class-members': linesBetweenClassMembers,
'member-delimiter-style': memberDelimiterStyle,
'member-ordering': memberOrdering,
Expand Down

0 comments on commit d55211c

Please sign in to comment.