GithubHelp home page GithubHelp logo

roald87 / tcblack Goto Github PK

View Code? Open in Web Editor NEW
96.0 20.0 11.0 2.01 MB

Opnionated code formatter for TwinCAT.

License: MIT License

C# 98.27% Batchfile 0.07% CSS 1.65%
formatter twincat3 twincat industrial-automation beckhoff beckhoff-twincat-plc beckhoff-twincat plc plc-programming

tcblack's Issues

TcBlackCore can not be build

When trying to build the TcBlackCore project I get the following error:

Unable to get MD5 checksum for the key file "TcBlackCoreSign.pfx". Could not find file 'C:\Users_username_\source\repos_username_\TcBlack\src\TcBlackCore\TcBlackCoreSign.pfx'.

This file is mentioned in the solution explorer, but is not included in the repo.

After removing the file in the solution explorer the solution could be build.

Add support for PUBLIC FINAL/ABSTRACT

The following combinations are possible:

FUNCTION_BLOCK PUBLIC FINAL SomeFB
FUNCTION_BLOCK INTERNAL FINAL SomeFB

FUNCTION_BLOCK PUBLIC ABSTRACT SomeFB
FUNCTION_BLOCK INTERNAL ABSTRACT SomeFB

METHOD PUBLIC ABSTRACT METH : BOOL
METHOD PRIVATE ABSTRACT METH : BOOL
METHOD PROTECTED ABSTRACT METH : BOOL
METHOD INTERNAL ABSTRACT METH : BOOL

Override automatic type detection of line ending and indentation

Currently if TcBlack will detects a single \r\n in a .TcPOU file it will use \r\n as a line ending. Similarly for the indentation: if it finds a single \t in a file it will use that one for the entire file.

It would be nice to override this behavior. For example in case there is a single \t in the file, but everywhere else four spaces are used.

Also this would allow for more indentation types then the current options of tabs or four spaces. Finally this would allow for an easy way to standardize the indentation across an entire project.

Regex for variable definition fails on string which includes semi colon or closing bracket

Losing the initialization portion if there's a semicolon inside the string
image

My initial idea was negative lookahead in the Tokenize method.

+ $@"{unit_pattern}{possible_space}{initialization}(?:;){comment}";

(?:;(?!.*;))
This negative lookahead would fail if there's a semi colon in the comment portion of the line also.

But that gives me even weirder results with the assignment operator now showing up.
image

Make command line interface to run TcBlack

  • Implement safe mode
    • Get hash before and after compile
  • When selecting a single file, find plcproj and sln file automatically
  • Read TcPou file(s)
  • Reformat files
  • Make a .bak copy of the original file
  • Write reformatted code in in original file

How to insert a tab in windows command prompt when you want to use tabs for indentation

I could not figure out how to format using the tab as an indentation in the windows command prompt. I tried:

  • pasting it and turning on/off the option where special characters are converted in the command prompt properties
  • using --indentation "\t"

The work around I found was to make a bat file with the following content and run that one.

> TcBlack.exe --indentation "	" -p C:\Some\Project\PLC.plcproj 

Replace complex regex in Tokenize

Currently the VariableDeclaration.Tokenize() method in TcBlackCore has quite a complex regular expression to separate all the different components. For example to close #35 a two step regex was needed. It might be a better idea to replace the regex with a a finite state machine as also discussed here. Example of finite state machine.

Show how many files were reformatted

Maybe non-verbose mode shows the number of reformatted files:

> TcBlack.exe --filenames C:\SomeFile.TcPOU C:\SecondFile.TcPOU
...
All done! Formatted 1 of total 2 files.

And the verbose mode (-v --verbose) also shows which files were reformatted

> TcBlack.exe --verbose --filenames C:\SomeFile.TcPOU C:\SecondFile.TcPOU
...
All done! Formatted 1 of total 2 files:
 - C:\SomeFile.TcPOU

And if none were formatted:

> TcBlack.exe --filenames C:\SecondFile.TcPOU
...
All done! No files were formatted.

Raise exception when no plcproj or sln file is found

If you format in safe mode and it either fails to find a . plcproj file and/or a .sln file it will still do the formatting.

Make it such that the user receives an error message and it aborts the formatting.

  • Program should handle the file not found exception
  • Add test for plcproj not found
  • Add test for sln file not found

GUI/Integration into Visual Studio for TcBlack

Is it possible to add an GUI/Integration to Visual Studio for TcBlack, the same way that StWeep is integrated into Visual Studio? Would be nice to have an open-source alternative to StWeep.

Prevent insert of := in array limits

Turns

Buffer: ARRAY[0..TcUnit.GVL_Param_TcUnit.xUnitBufferSize - 1] OF BYTE;

into

Buffer: ARRAY[0..TcUnit.GVL_Param_TcUnit.xUnitBufferSize := - 1] OF BYTE;

but should not change

Format implementation of files

Currently only looks like the Declaration part of files are formatted. I'd like to look at getting the Implementation part of files included. Did you have any specific ideas/ways you were thinking of doing this?

Removes FB name from declaration when using FINAL

Removed the FB name. My initial guess is due to the FINAL descriptor.
image

With a FINAL method also weird behavior with an extra colon added.
image

If you point me in the right direction I can take a look at it.

Remove assembly signing

Github secrets are not available to forked repos. That's why the piplines of the PR's failed from others than mine.

Singing would only be necessary in case of publishing a release. So, it should be possible to remove the required signature when it goes into the pipeline for only builds and tests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.