roald87 / tcblack Goto Github PK
View Code? Open in Web Editor NEWOpnionated code formatter for TwinCAT.
License: MIT License
Opnionated code formatter for TwinCAT.
License: MIT License
E.g. nVar : INT; {info 'TODO: should get another name'}
Recognize PUBLIC, PRIVATE, PROTECTED, INTERNAL
in functions and function blocks.
And build it than using the same one.
Search for the line ending and indentation type (spaces vs tabs) in the file and use the same type when calling Format()
.
If you give a .plcproj
file instead of a .TcPOU
file, it should reformat all the files in the project.
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.
Better name which is also used in the docs.
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
Currently it removes spaces from
// In
fbInst : FB_WithName(Name:='Text with spaces');
// Out
fbInst : FB_WithName(Name:='Textwithspaces');
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.
Use // fmt: off
and end with // fmt: on
to turn off formatting of a certain code section.
Losing the initialization portion if there's a semicolon inside the string
My initial idea was negative lookahead in the Tokenize method.
(?:;(?!.*;))
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.
Currently TcBlack.exe
only works under the following conditions:
build.log
needs to be present when executed in non-safe mode.TcBlack.exe
is executed directly from its own folderAfter formatting a text with the TcBlackExtension, there is no way to undo it. you can't undo it with Ctrl + Z. Not sure how to implement this yet.
If you add a few extra lines of code and do not save the file and then format, TcBlack will remove the code you just added. Only if you save the file it will correctly format it.
TcBlackExtension v0.1.0
I could not figure out how to format using the tab as an indentation in the windows command prompt. I tried:
--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
Calling Format()
on these will return the original string.
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.
Would save a lot of code, since these are used everywhere. Question is does it work with the unit tests?
Other folders do not contain files which should be build.
Currently if there is a file which is called .slnbak
then it can't find a single .sln
file and thus it will return an empty sln path.
Would you consider adding support to the vs extension for VS2019?
Thanks.
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.
Add --line-length
option for CLI to change the line length.
Currently it does this:
-aLINT : ARRAY[-1..1] OF LINT;
+aLINT : ARRAY[ - 1..1] OF LINT;
This should not happen.
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.
Currently the devenvPath
is hard coded in TcProjectBuilder
to the default path "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/devenv.exe"
for VS2017. Would be nice to make it independent of the system and VS version.
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.
Or else there will be unnecessary diffs, since the VS TwinCAT editor automatically adds these indents.
This is to prevent diffs like these (double empty lines are automatically removed):
VAR
var1 : REAL;
-
-
+
var2 : REAL;
END_VAR
If you run TcBlack for the first time and in non-safe mode it will raise an exception because the build.log
file is not there. If you first run it in safe mode the file gets created.
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
I couldn't build TcBlackExtension when I added TCatSysManager.dll
to the project, but it should be possible to do it like that according to Gerhard Barteling.
Currently the static code analyses is run, but there is no clear indication when a warning was raised due to this. For example this one:
Not sure how to indicate failure. Somehow need to return a number other than 0 to make the pipeline fail.
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?
Then it is clearer where it failed.
// in
METHOD Something
VAR_INPUT
END_VAR
VAR
END_VAR
// out
METHOD Something
The new build method implemented with #47 is much slower than the previous solution. Is there a way to speed things up?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.