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

WTG3007 code fix adds extra new lines when overridden member is adjacent to a #region or #endregion #200

Open
andrewhongnsw opened this issue Feb 7, 2023 · 1 comment

Comments

@andrewhongnsw
Copy link

The code fix to remove pointlessly overridden methods works as expected, except for cases where the overridden method comes immediately after, or comes immediately before a #region or #endregion directive.

In such cases, extra new lines are left in the returned document.

For example a code fix on the following snippet:

#region Form Setup
		protected override void OnShown(EventArgs e)
		{
			base.OnShown(e);
		}

		void SetControlModuleIDs()

Will lead to:

#region Form Setup



		void SetControlModuleIDs()

This leads to SA1507 errors on the lines between the #region directive and the following method.

@andrewhongnsw andrewhongnsw changed the title WTG3007 code fix adds extra new lines when overridden member is adjacent to to a #region or #endregion WTG3007 code fix adds extra new lines when overridden member is adjacent to a #region or #endregion Feb 7, 2023
@yaakov-h
Copy link
Member

yaakov-h commented Feb 7, 2023

This is somewhat expected. We remove the method, but keep exterior trivia (leading and trailing). If there are comments there, or in your case #region trivia, we want to keep it.

If we want to get fancy and start balancing the trivia ourselves, then we'd have to pick one set of rules to use. SA1507 doesn't like the multiline whitespace, but it is also feasible for a project to have the opposite and require two blank lines - or to require no blank lines at all.

SA1507 also includes a code fix, so you should be able to immediately fix up that secondary warning too.

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

No branches or pull requests

2 participants