Skip to content

Add code formatting rules #690

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

Merged
merged 72 commits into from
Jan 13, 2017
Merged

Add code formatting rules #690

merged 72 commits into from
Jan 13, 2017

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Jan 12, 2017

  • Adds the following rules

    • PSPlaceOpenBrace
    • PSPlaceCloseBrace
    • PSUseConsistentIndentation
  • These rules are disabled by default and can enabled only through settings.

  • Adds an abstract class called ConfigurableRule to allow easy configuration of rules from settings.

  • An accompanying settings file (Settings/CodeFormatting.psd1) is provided to run only the formatting rules.


This change is Reviewable

Kapil Borle added 30 commits December 20, 2016 19:09
We do not want formatting rules to be run by default whenever scriptanalyzer is invoked. However, the engine doesn't provide a way to disable a given built-in rule without messing with the input parameters or input settings file. Hence we add this parameter to the formatting rules so that they are not run by default whenever scriptanalyer is invoked.
Copy link
Contributor

@daviwil daviwil left a comment

Choose a reason for hiding this comment

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

This looks awesome! A couple comments, but overall this is a great start.

@@ -0,0 +1,30 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copyright headers might be necessary on the new files

foreach (var settingKey in settings.Keys)

var settingsKeys = new string[settings.Keys.Count];
settings.Keys.CopyTo(settingsKeys, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do settings get removed from the dictionary in the loop?

Copy link
Author

Choose a reason for hiding this comment

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

Assigning elements to the dictionary while iterating over it was causing problems. After creating a separate copy of the keys the problem went way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh yes, makes sense!

<value>Place close braces</value>
</data>
<data name="PlaceCloseBraceDescription" xml:space="preserve">
<value>Place close brace show be on a new line by itself.</value>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be "Close brace should be on a new line by itself." ?

@daviwil
Copy link
Contributor

daviwil commented Jan 13, 2017

Looks good!

@kapilmb
Copy link
Author

kapilmb commented Jan 13, 2017

Thanks @daviwil

I just renamed the ConfigurableScriptRule class to ConfigurableRule. As soon as the tests pass, I will merge this.

@daviwil
Copy link
Contributor

daviwil commented Jan 13, 2017

Sounds good to me!

@kapilmb kapilmb merged commit fcd9a4e into development Jan 13, 2017
@kapilmb kapilmb deleted the kapilmb/CodeFormatting branch January 13, 2017 22:23
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