Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shellcheck: add code actions to disable rule #1069

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ThomasFaivre
Copy link

Following my comment in #933, I ended up finishing my draft.
It is now fully functionnal:

  • handle indentation
  • handle existing directives
  • make tests
  • handle multiline commands
  • insert sorted disable directives
  • Stuff I'm missing

Tested with Neovim (NVIM v0.10.0-dev-1846+gf31f260f0).

Therefore, I would like your opinion on the implementation.
I have already spotted some room for improvements:

  • use directive.ts existing module
  • use tree sitter (multiline detection, indentation maybe?, disable whole scope?)
  • split code into different modules
  • some doc on public methods. Maybe on private as well?
  • disable all errors of a given line (for the line and for the whole file)

What do you think?
Thanks!

Implements bash-lsp#933.

Always add a code action to disable a given diagnostic for a given line
or for the whole file.
This patch handles:
 * indentation
 * existing directive. It also sorts the disable directives if any
 * multi-line command

Add corresponding tests.

Signed-off-by: Thomas Faivre <[email protected]>
Copy link
Collaborator

@skovhus skovhus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Seems like a great starting point. I suggest adding some unit test and the. After that see if we should improve the implementation.

@@ -222,7 +222,7 @@ describe('server', () => {
{} as any,
)

expect(result).toHaveLength(1)
expect(result).toHaveLength(3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us check what all the code actions are about. Consider just doing a snapshot test of the entire result object.

result,
}: {
document: TextDocument
uri: string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason to pass in the uri if we have the document.

lineNb,
}: {
document: TextDocument
lineNb: number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the nb abbreviation and postfix seems unnecessary.

})
}

// TODO: use directives module
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


private static getIndentation(line: string): string {
const match = line.match(/^([\s]*)/)
if (match && match[1]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth exploring using the AST for this.

@ambroisie
Copy link

@ThomasFaivre are you going to be working on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants