TaoK / PoorMansTSqlFormatter

A small free .Net and JS library (with demo UI, command-line bulk formatter, SSMS/VS add-in, notepad++ plugin, winmerge plugin, and demo webpage) for reformatting and coloring T-SQL code to the user's preferences.
http://www.architectshack.com/PoorMansTSqlFormatter.ashx
GNU Affero General Public License v3.0
969 stars 268 forks source link

Problem with PoorMansTSqlFormatter. Commented lines within end of insert statement not properly formatted. #215

Open RaghavendraDasara opened 5 years ago

RaghavendraDasara commented 5 years ago

Example : Code before formatting INSERT INTO @test ( ID, Name

---- /[minify]/ /[noformat]/ -- [minify]

-- -- [/minify] -- [/noformat] /[/noformat]/ ---- /[/minify]/

)

    SELECT 1,
        'Test poor man'
        --<Age>
        --<DOB>

Example : Code after formatting

INSERT INTO @test ( ID, Name ) ---- /[minify]/

-- [/minify]

-- [/noformat] /[/noformat]/ ---- /[/minify]/ SELECT 1, 'Test poor man'

--

i used minify and noformat option to avoid formatting for within that block still it is formatting.i don't want to format some of the lines.Please resolve the issue as early as possible. Expected result : INSERT INTO @test ( ID, Name

---- /[minify]/

-- [/minify]

-- [/noformat] /[/noformat]/ ---- /[/minify]/

)

SELECT 1, 'Test poor man'

--

TaoK commented 5 years ago

Hi, it's a little difficult to follow what you're saying here, partially because of formatting confusion I suspect.

I think you're saying that your comments "--" and "--" are being deleted during the formatting, and that you would like them to not be deleted. Is this correct?

The reason these comments are being deleted (I assume - it's hard to follow your example) is because you are using the "minify" instruction to the formatter. "minify" means "make it as small as possible, removing as much whitespace as possible and removing all comments".

The "noformat" and the "minify" instructions are separate and intended to achieve different things. "noformat" means "please leave it as it is, I like it like that", and "minify" means "please make it as compact as possible".

Please let me know if this addresses your concern, or if I've misunderstood your intent.

RaghavendraDasara commented 5 years ago

Please go through below code.If you have any concerns, kindly let me know.

Example Code: INSERT INTO @test ( ID, Name --Commented Line 1 --Commented Line 12 )

SELECT 1, 'Test poor man'

After Applying "Format T-SQL Code" in SSMS Commented lines moving out from insert into parenthesis. You can see below example: INSERT INTO @test ( ID, Name ) --Commented Line 1 --Commented Line 2 SELECT 1, 'Test poor man'

Expected Result : Code should be formatted and comment lines should be within insert statement parenthesis : INSERT INTO @test ( ID, Name --Commented Line 1 --Commented Line 2 )

SELECT 1, 'Test poor man'

RaghavendraDasara commented 5 years ago

Code before formatting : INSERT INTO @test ( ID, -- Comment before last column Name -- Comment after last column and before closing parenthesis ) -- Comment after closing parenthesis SELECT 1, 'Test poor man'


After Applying "Format T-SQL Code" in SSMS INSERT INTO @test ( ID, -- Comment before last column Name ) -- Comment after last column and before closing parenthesis -- Comment after closing parenthesis SELECT 1, 'Test poor man'


Expected : INSERT INTO @test ( ID, -- Comment before last column Name -- Comment after last column and before closing parenthesis ) -- Comment after closing parenthesis SELECT 1, 'Test poor man'

ChristianW-1 commented 4 years ago

Hi @TaoK , I will try to bring some light to this issue to see if you could assists with a solution. Refering to the example above. The problem is that the complete line with the comment is moved to another place in the code.

Having a look at the example below:

INSERT INTO @test ( ID, -- Comment before last column Name -- Comment after last column and before closing parenthesis ) -- Comment after closing parenthesis SELECT 1, 'Test poor man'

The line:

-- Comment after last column and before closing parenthesis

is moved to after the line after the closing parentheses.

Using [noformat]-tag the formatting of the code is still performed so the commented line is moved to after closing parantheses line. Using [noformat] is not an option to solve this issue as it is right now. The "noformat" (please leave it as it is) does not work for my example.