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
Recognize PUBLIC, PRIVATE, PROTECTED, INTERNAL
in functions and function blocks.
// in
METHOD Something
VAR_INPUT
END_VAR
VAR
END_VAR
// out
METHOD Something
Other folders do not contain files which should be build.
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?
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 folderIf 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
Search for the line ending and indentation type (spaces vs tabs) in the file and use the same type when calling Format()
.
Currently it does this:
-aLINT : ARRAY[-1..1] OF LINT;
+aLINT : ARRAY[ - 1..1] OF LINT;
This should not happen.
E.g. nVar : INT; {info 'TODO: should get another name'}
Calling Format()
on these will return the original string.
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.
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
If you give a .plcproj
file instead of a .TcPOU
file, it should reformat all the files in the project.
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.
Add --line-length
option for CLI to change the line length.
The new build method implemented with #47 is much slower than the previous solution. Is there a way to speed things up?
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.
After 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.
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
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.
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.
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 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.
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
Would you consider adding support to the vs extension for VS2019?
Thanks.
Better name which is also used in the docs.
And build it than using the same one.
Currently it removes spaces from
// In
fbInst : FB_WithName(Name:='Text with spaces');
// Out
fbInst : FB_WithName(Name:='Textwithspaces');
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.
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.
Would save a lot of code, since these are used everywhere. Question is does it work with the unit tests?
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.
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
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.
Then it is clearer where it failed.
Use // fmt: off
and end with // fmt: on
to turn off formatting of a certain code section.
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.
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.