Download the PHP package petk/normalizator without Composer
On this page you can find all versions of the php package petk/normalizator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download petk/normalizator
More information about petk/normalizator
Files in petk/normalizator
Package normalizator
Short Description Normalize files in Git repository
License MIT
Homepage https://github.com/petk/normalizator
Informations about the package normalizator
Normalizator
Command line tool written in PHP that checks and fixes trailing whitespace, LF or CRLF newline characters, redundant trailing final newlines, file permissions and similar in given files.
Features
- Checks file permissions
- Trims trailing whitespace characters
- Trims redundant final newlines
- Trims redundant leading newlines
- Inserts missing final newline
- Trims redundant newlines in the middle of the file
- Converts and syncs EOL (end of line) characters
- Cleans spaces before tabs in the indentation part of the line
- Checks file extensions
- Checks file and directory names if they contain any special characters (spaces, non-ASCII characters, etc.)
- Checks file encodings
- Checks indentation style
Installation
Normalizator is a simple Phar executable file that can be downloaded from GitHub:
Or:
By moving it to /usr/local/bin
it can be accessed accross your system:
Update
Update normalizator to the latest version:
About
There is a recurring and never-ending issue in many code projects with trailing whitespace, missing final newlines at the end of the files, too many redundant newlines, different end of line characters, misused permissions and similar.
Beside the multiple preferred coding styles, also certain editors behave
differently and some automatically fix these when saving files. Some utilize
.editorconfig
file by default and some leave files intact.
Git also provides several configuration options to detect and deal with these issues.
Although it is not mandatory for all files to have these issues fixed, a more consistent and homogeneous approach brings less cognitive load in commits and a better development experience in certain text editors and IDEs.
This tool aims to bring an initial solution to this issue and provides a more consistent set of source code files across the code repository with a simplistic yet still useful and powerful enough approach to tidy all files in a given Git repository, directory, or a path using command line.
Docker
There is also a Docker image available to run the tool inside a container:
Requirements
To use normalizator, system needs to have PHP 8.2 or greater installed with the following PHP extensions:
- fileinfo
- filter
- intl
- mbstring
- phar
Usage
Check files (dry run) without modifying any file:
Fix and overwrite files:
Passing paths
Paths or files can be passed as a space separated arguments:
The --not
option skips given paths or files:
File encoding
For non-ASCII and non-UTF-8 file encodings, option --encoding
or short -c
tries to convert file content encoding to UTF-8:
See also:
Trailing whitespace
Normalizator can trim trailing whitespace characters in text files:
To fix files:
Indentation style
Indentation style can be checked with:
Indentation size is set to 4 (one tab equals to 4 spaces). Indentation size can
be changed with the --indentation-size
option. For example, the following will
set indentation size to 2:
Space before tab
To clean all spaces before tabs in the indentation:
EOL normalization
This normalizes the EOL (end of line) style (LF vs CRLF):
According to POSIX,
a line is a sequence of zero or more non-<newline>
characters plus a
terminating <newline>
character. Files should normally have at least one
final newline character.
C89 standard and above mention a final newline:
A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.
Newline characters:
- LF (
\n
) (*nix and Mac, default) - CRLF (
\r\n
) (Windows) - CR (
\r
) (old Mac, obsolete)
It is possible to set EOL character with the
eol
Git attribute if some files
require specific EOL:
Normalizator will take the Git attribute setting into account.
To override the EOL characters for all files in the given path:
Redundant leading EOL
Final EOL normalization
Optionally, you can set the maximum number of allowed final EOLs by passing a number. In case of a missing final EOL, one will be appended. This will allow up to 2 final EOLs:
Redundant middle EOL
To trim redundant EOLs in the middle of the text or code:
Permissions normalization
This syncs permissions of given files and directories. Symbolic links are not affected.
This mostly applies for *nix systems.
- Files should usually have 0644 permissions.
- Directories should usually have 0755 permissions.
- Executable files should usually have 0755 permissions.
- Protected files have 0444 permissions.
Permissions in the .git
directory:
On systems with umask 002 (Ubuntu) these permissions are off by 2. So they are a bit more relaxed and defaults are:
- Files: 0664
- Directories 0775
- Executables 0755
- Protected files are still 0444
File extension normalization
To normalize file extensions:
This will adjust file extensions, for example from .JPEG
to .jpg
and similar.
Filename normalization
To normalize names of files and directories:
This fixes names of files and directories so that they don't contain whitespaces or special characters that might cause issues in certain occassions.
Documentation
License and contributing
Contributions are welcome by forking the repository on GitHub. This repository is released under the MIT license.
All versions of normalizator with dependencies
ext-fileinfo Version *
ext-filter Version *
ext-intl Version *
ext-mbstring Version *
ext-phar Version *
psr/container Version ^2.0
psr/event-dispatcher Version ^1.0
psr/simple-cache Version ^3.0
symfony/console Version ^7.0