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

Block ignore is not applied to all back-to-back blocks #421

Closed
echasnovski opened this issue Mar 27, 2022 · 1 comment · Fixed by #422
Closed

Block ignore is not applied to all back-to-back blocks #421

echasnovski opened this issue Mar 27, 2022 · 1 comment · Fixed by #422
Labels
bug Something isn't working

Comments

@echasnovski
Copy link

When --stylua: ignore start/end comments are applied back-to-back, they take effect on every second ignored block. This might be considered as a non-issue because they can be merged into one single ignored block, but it might be inconvenient when they are separated with large comment block.

My understanding is that "this comment must be preceding a statement (same as -- stylua: ignore), and cannot cross block scope boundaries" holds here, although I am not sure about it.

Steps to reproduce:

  • Create file tmp.lua with the following contents:
--stylua: ignore start
local a   =   1
--stylua: ignore end

--stylua: ignore start
local b   =   2
--stylua: ignore end

--stylua: ignore start
local c   =   3
--stylua: ignore end

-- Some very large comment

--stylua: ignore start
local d   =   4
--stylua: ignore end
  • Run stylua tmp.lua.

Currently observed output:

--stylua: ignore start
local a   =   1
--stylua: ignore end

--stylua: ignore start
local b = 2
--stylua: ignore end

--stylua: ignore start
local c   =   3
--stylua: ignore end

-- Some very large comment

--stylua: ignore start
local d = 4
--stylua: ignore end

Details:

  • Version of StyLua: 0.12.5
  • OS: Xubuntu 20.04.
@JohnnyMorganz JohnnyMorganz added the bug Something isn't working label Mar 27, 2022
@JohnnyMorganz
Copy link
Owner

Yeah, this is a bug - it seems as though we are not correctly re-opening an ignore section when we see the --stylua: ignore start comment.

This code is actually parsed as these separate statements:

--stylua: ignore start
local a   =   1
---------------------------
--stylua: ignore end

--stylua: ignore start
local b   =   2

where --stylua: ignore end and --stylua: ignore start are both leading trivia of the local b statement.
We are probably exiting early when we see the --stylua: ignore end comment in the leading trivia, but we should continue scanning in case we find another ignore comment afterwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants