Visual Studio Mac Format Code



Lint (code quality), Format and Auto-fix your groovy files and Jenkinsfile

Visual Studio Code extension embedding npm-groovy-lint, itself embedding CodeNarc

  • You can configure the rules by defining a .groovylintrc.json file
  • If you use CI, you can integrate Mega-Linter in your workflow, to make sure all your sources (groovy and other) are clean

Features

CommandDescriptionAccess
Analyze codeLint the code of the current fileCtrl+Shit+F9
Contextual
Status bar
Commands
FormatFormat the code of the current fileShift+Alt+F
Contextual
Commands
Fix all auto-fixable problemsFix the code of the current fileContextual
Commands
Lint folderLint all applicable files of a folderContextual
Fix single errorApply quick fix for a single problemQuick Fix
Diagnostic
Fix rule in entire fileApply quick fix for all problems related to the same rule in the current fileQuick Fix
Diagnostic
Disable rule for this lineDisable rule only for current lineQuick Fix
Diagnostic
Disable rule for this entire fileDisable rule in the entire fileQuick Fix
Diagnostic
Disable rule for this entire projectUpdates configuration file
(usually .groovylintrc.js in root folder) to disable this rule)
Quick Fix
Diagnostic
  • Contextual: right click in source code or on folder
  • Commands: Ctrl+Shift+P then type command name
  • Status bar: GroovyLint status item at the bottom right
  • Quick Fix: Hover an underlined part of the code after a lint, click Quick Fix then select action to perform
  • Diagnostic: Right click on a diagnostic in Problems section

Extension Settings

ParameterDescriptionDefault
groovyLint.enableControls whether GroovyLint is enabled or nottrue
groovyLint.lint.triggerRun the linter on save (onSave), on type (onType) , or on user requestonSave
groovyLint.format.enableControls whether the groovy formatter is enabled or nottrue
groovyLint.fix.enableRun the auto-fixer on save (onSave), on type (onType) , or on user requesttrue
groovyLint.fix.triggerRun the fixer on save (onSave), or on user requestuser
groovyLint.basic.loglevelLinting error level (error, warning,info)info
groovyLint.basic.verboseTurn on to have verbose logsfalse
groovyLint.basic.configNPM groovy lint configuration file.groovylintrc.json
groovyLint.debug.enableDisplay more logs in VsCode Output panel (select 'GroovyLint') for issue investigationfalse
groovyLint.java.executableOverride java executable to use
Example: C:Program FilesJavajdk1.8.0_144binjava.exe
java
groovyLint.java.optionsOverride java options to use'-Xms256m,-Xmx2048m'
groovyLint.insight.enableAllow to send anonymous usage statistics used only to improve the tool (we will of course never send your code)true

Troubleshooting

  • Node.js version 12 or higher is required to run this extension. If you can't upgrade, you can use nvm to have different node versions on your computer

  • Java version 8 or higher is required to run this extension

  • As CodeNarc is run in background with java/groovy, performances could be improved on large files (do not hesitate to provide advices !)But do not worry, as the groovy linting is provided by a background local server, your VsCode won't be slowed.

Contribute

Contributions are very welcome on :

  • NPM Groovy Lint (linter called by this extension)

Please follow Contribution instructions

Special Thanks

  • yuvmel, for his great support on #18 that allowed VsCode Groovy Lint to work much better on Mac, Linux, and with other diagnostic extensions

Release Notes

[1.3.0] 2020-11-15

  • Upgrade to npm-groovy-lint v8.0.0
    • Upgrade to CodeNarc 2.0.0
    • Improve performances
    • Fix bugs

[1.2.7] 2020-09-04

  • Upgrade to npm-groovy-lint v7.5.4

[1.2.6] 2020-09-02

  • Upgrade to npm-groovy-lint v7.5.2
  • Fix crash when empty groovy file
  • Fix crash when non-sense groovy file

[1.2.3] 2020-08-29

  • Fix bug on Windows when username contains space(s)

[1.2.2] 2020-08-21

  • Allow user to hide future npm-groovy-lint error messages
  • Manage correctly user choice Never for tabs auto-replacement by spaces
  • Upgrade to npm-groovy-lint v7.4.0

[1.2.0] 2020-08-15

  • Upgrade to npm-groovy-lint v7.3.0
    • Allow to link to CodeNarc RuleSet files from .groovylintrc.json, using property 'codenarcRulesets'. Warning: doing so means that all other properties of config file will be ignored.

[1.1.1] 2020-08-11

  • Upgrade to npm-groovy-lint v7.2.0
    • Upgradejava-caller to v2.0.0 : better performances

[1.1.0] 2020-08-10

  • Upgrade to npm-groovy-lint v7.1.0
    • Externalize JavaCaller class into a separate package java-caller and use it

PREVIOUS VERSIONS

See complete CHANGELOG

-->

Visual Studio for Mac is a powerful developer tool that reinforces Microsoft’s “mobile-first”, “cloud-first”, and “any developer, any platform, any device” strategy. With the author’s guided expertise and extensive code samples, you will understand how to leverage the most useful tools in Visual Studio for Mac, the code.

You can define code style settings per-project by using an EditorConfig file, or for all code you edit in Visual Studio on the text editor Options page. For C# code, you can also configure Visual Studio to apply these code style preferences using the Code Cleanup (Visual Studio 2019) and Format Document (Visual Studio 2017) commands.

  • For format document you need to click CTRL+ALT+L combination (just like in IDEA Studio) in opened, and saved document in HDD. For Mac CMD+ALT+L (i don't have a MacBook.) Extension Settings. This extension contributes the following settings: astyleFormat.show-message: Show message when formatting. By default is true.
  • This topic applies to Visual Studio on Windows. For Visual Studio for Mac. Format Document. Toggle between the code editor window and the Peek Definition window.
  • Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows. Download Visual Studio Code to experience a redefined code editor, optimized for building and debugging modern web and cloud applications.

Note

This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Editor behavior in Visual Studio for Mac.

Code styles in EditorConfig files

Code style settings for .NET can be specified by adding an EditorConfig file to your project. EditorConfig files are associated with a codebase rather than a Visual Studio personalization account. Settings in an EditorConfig file take precedence over code styles that are specified in the Options dialog box. Use an EditorConfig file when you want to enforce coding styles for all contributors to your repo or project.

You can manually populate your EditorConfig file, or you can automatically generate the file based on the code style settings you've chosen in the Visual Studio Options dialog box. This options page is available at Tools > Options > Text Editor > [C# or Basic] > Code Style > General. Click Generate .editorconfig file from settings to automatically generate a coding style .editorconfig file based on the settings on this Options page.

Code styles in the Options dialog box

Code style preferences can be set for all of your C# and Visual Basic projects by opening the Options dialog box from the Tools menu. In the Options dialog box, select Text Editor > [C# or Basic] > Code Style > General.

Each item in the list shows a preview of the preference when selected:

Options set in this window are applicable to your Visual Studio personalization account and aren't associated with a particular project or codebase. In addition, they aren't enforced at build time, including in continuous integration (CI) builds. If you want to associate code style preferences with your project and have the styles enforced during build, specify the preferences in an .editorconfig file that's associated with the project.

Preference and severity

For each code style setting on this page, you can set the Preference and Severity values using the drop-downs on each line. Severity can be set to Refactoring Only, Suggestion, Warning, or Error. If you want to enable Quick Actions for a code style, ensure that the Severity setting is set to something other than Refactoring Only. The Quick Actions light bulb , error light bulb , or screwdriver icon appears when a non-preferred style is used, and you can choose an option on the Quick Actions list to automatically rewrite code to the preferred style.

Enforce code styles on build

Starting in Visual Studio 2019 version 16.8, which includes the .NET 5.0 RC2 SDK, you can enforce the .NET coding conventions on build for all .NET projects. At build time, .NET code style violations will appear as warnings or errors with an 'IDE' prefix. This enables you to strictly enforce consistent code styles in your codebase.

Apply code styles

You can configure the Format Document command (Edit > Advanced > Format Document) to apply your code style settings (from an EditorConfig file or Code Style options) along with the regular formatting that it does (such as indentation). If an .editorconfig file exists for the project, those settings take precedence.

Note

Applying code styles by using the Format Document command is only available for C# code files. This is an experimental feature.

Configure which settings you want Format Document to apply on the Formatting options page.

Tip

Format

Rules configured with a severity of None don't participate in code cleanup but can be individually applied via the Quick Actions and Refactorings menu.

The first time you trigger the Format Document command, a yellow info bar prompts you to configure your code cleanup settings.

For C# code files, Visual Studio 2019 has a Code Cleanup button at the bottom of the editor (keyboard: Ctrl+K, Ctrl+E) to apply code styles from an EditorConfig file or from the Code Style options page. If an .editorconfig file exists for the project, those are the settings that take precedence.

Tip

Visual Studio Mac Format Code Keys

Rules configured with a severity of None don't participate in code cleanup but can be individually applied via the Quick Actions and Refactorings menu.

First, configure which code styles you want to apply (in one of two profiles) in the Configure Code Cleanup dialog box. To open this dialog box, click the expander arrow next to the code cleanup broom icon and then choose Configure Code Cleanup.

Visual Studio Community

After you've configured code cleanup, you can either click on the broom icon or press Ctrl+K, Ctrl+E to run code cleanup. You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

Visual Studio Code Format Code Command

If you want your code style settings to be applied every time you save a file, you may like the Code Cleanup on Save extension.

Visual Studio Mac Format Codes

See also