How to specify custom standard with bruli/php-git-hooks library - githooks

I am using this PHP Library here https://github.com/bruli/php-git-hooks, this library uses phpcs (https://github.com/squizlabs/PHP_CodeSniffer)
I have a php-git-hooks.yml config file like this
pre-commit:
enabled: true
execute:
phpcs:
enabled: true
standard: my-custom-cs.xml
I am trying to use a custom standards file. I get this error
[PhpGitHooks\Module\Configuration\Contract\Exception\InvalidPhpCsStandardException]
Invalid phpcs standard <my-custom-cs.xml>
Specifying a built in standard such as standard: PSR2 does work.
How can I specify a custom file? Judging by the libraries code at https://github.com/bruli/php-git-hooks/blob/528a9a4c5905e9f5ca7bdb55f5111dd4fe22ca9c/src/PhpGitHooks/Module/Configuration/Domain/PhpCsStandard.php#L22 this may not even be possible?

you need to add the new standard as normal you do it. For example i add the WPCS. I clone into the phpcs Standard folder /vendor/****/Standard and i follow the instruction from https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards as standard alone installationa and it detect pretty well.

Related

Is there any extension for vscode to make it support C intelligence only (without C++)?

Due to my job, I have to develop software with only C but not C++.
It will be good that when I write class A {}; Vscode will display an error or a warning.
Now I use clangd, it will be great if some settings can satisfy.
Clangd will correctly issue diagnostics for C++-only constructs, if it's parsing your file in C mode.
So it's a matter of making sure clangd is parsing your files in the correct language mode.
If your file's extension is unambiguously a C-language extension (for example, .c), then clang should parse the file in C mode automatically.
If the extension is ambiguous, like .h, then clangd attempts to choose the language heuristically, which can sometimes give a wrong answer. In this case, you can specify the language explicitly in the file's compile command, for example by adding -x c-header to specify "parse as a C header".
One way to do this is using CompileFlags: Add: in the clangd config file. For example, to specify that all .h files in the project are C headers, you might add the following to the project .clangd file:
If:
PathMatch: .*\.h
CompileFlags:
Add: [-xc-header]

How to create cmake library that expects an external header file

I feel like I'm missing some key idea with this one.
I have a library that I'd like to create a CMakeLists.txt file for. I want to link against it with different applications.
This library expects a conf.h file to be defined. The application has to provide this. The library expects it. What is this relationship called?
My current solution in CMakeLists.txt is to have a variable like:
...
target_include_directories(lib PUBLIC
${CONF_DIR}
)
And then have CONF_DIR be defined by the application. This is uncool, because I can't have multiple applications linking against it.
The only other alternative is to keep a copy of the entire source library inside the application folder, which is also uncool.
I'm looking to maximize reusability. How do I approach this?
Side note: For anyone who's familiar, the library in question is STM32Cube's HAL library, and the pesky file is stm32h7xx_hal_conf.h.
This is a very common approach, when a library requires configuration. FreeRTOS would be another example.
I don't see the issue with modifying the target_include_directories for the library from the App's CMakeLists.txt.
Usually, I create a function to handle the library set-up. The call site would look something like this:
add_stm32_hal_lib(
PATH drivers/STM32H7xx_HAL_Driver
EXTRA_INCLUDES path/to/config
)
# ...
target_link_libraries(app PUBLIC stm32_hal)
The contents of the EXTRA_INCLUDES parameter get shoved into target_include_directories of the static library.
You can't do anything about this, so you'll have to copy the library code.
The header file is used during library compilation stage, so its code ends up being hardwired into the final binary. Because of this, if you want to change some parameters from the header, you need to recompile the library from scratch.
Ideally, the library should be rewritten in such way, that all parameters that are contained in the header can be set up dynamically, during the runtime, using some additional configuration API.

How can I get a protocol working under GNU-EFI?

I use GNU-EFI to develop UEFI apps. I have some trouble getting a protocol (EFI_SHELL_PROTOCOL) working under GNU-EFI. My compiler says that it is undefined. Should I include something? I already included efi.h and efilib.h. Do I need more?
Code that I tried:
EFI_SHELL_PROTOCOL shell;
The error that I got:
error: unknown type name ‘EFI_SHELL_PROTOCOL’; did you mean ‘EFI_OPEN_PROTOCOL’?
161 | EFI_SHELL_PROTOCOL shell;
The EFI_SHELL_PROTOCOL isn't part of the main UEFI interface, and is therefore not included in the main header files (e.g. efi.h) and not included in the main UEFI standard.
Instead, EFI_SHELL_PROTOCOL is just an optional extension (that may not exist, and I'd assume is only likely to exist when a shell is being used and provides it), with its own separate standard and its own separate header file.
Assuming you're using GNU's tools; the right files to include are probably efishellintf.h and efishellparm.h.
Currently, GNU-EFI does not support EFI_SHELL_PROTOCOL. It doesn't contain any related definitions about it.
If you want to use it with GNU-EFI, you can use this header file from edk2 (put it in inc folder, for example, inc/efishell.h). Then include this header file in inc/efi.h and add these lines:
lib/data.c:
EFI_GUID ShellProtocol = EFI_SHELL_PROTOCOL_GUID;
inc/efilib.h:
extern EFI_GUID ShellProtocol;
Rebuild your GNU-EFI and now you can use EFI_SHELL_PROTOCOL by locating it first.
EFI_SHELL_PROTOCOL *SP;
uefi_call_wrapper(BS->LocateProtocol, 3, &ShellProtocol, NULL, &SP);
The EFI_SHELL_PROTOCOL is fully documented in the UEFI Shell Specification (currently v2.2) which can be downloaded at https://uefi.org/specifications
GNU EFI does not currently implement EFI_SHELL_PROTOCOL or, indeed, all of the current UEFI Specification. For a reference implementation of the UEFI Shell Specification look at the EDK11 ShellPkg source code.

Get file extension in C

Is there a C library function to get the extension of file? I know that I can design a function on my own to get extension after '.' but not all files are stored with their extensions when we read them.
So you'd like to get the type of a file? Maybe the command 'file' in Linux is what you want. You can check its source code.
The file command in Linux uses a library called libmagic (don't confuse with libmagick) to check the 'magic' bytes in the file itself to determine the likely content type.
The library is fairly cross platform, it's well documented, for example here:
http://linux.die.net/man/3/libmagic

C: library for parsing configuration files and command line

I'm looking for some library with support for strict set of options (so non-existent options couldn't be set in config file) and possibility to also parse command line to override options from config file. Any ideas?
For command line, there is getopt or plentiful of code, some with more, some with less strange APIs, some in the form of open-codedness like getopt, others in table form with or without callback ability. As for config file, there is (lib)augeas if you need support for almost arbitrary formats.
Assuming you can use LGPL stuff in your project, there's http://www.hyperrealm.com/libconfig/, which appears, according to the docs, to have support in the API for setting values after a file has been parsed.

Resources