Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cphyc/fortran-linter
A simple fortran syntax checker, including automatic fixing of the code.
https://github.com/cphyc/fortran-linter
fortran linter python3
Last synced: 3 days ago
JSON representation
A simple fortran syntax checker, including automatic fixing of the code.
- Host: GitHub
- URL: https://github.com/cphyc/fortran-linter
- Owner: cphyc
- License: other
- Created: 2017-11-12T16:56:22.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-01-20T21:14:34.000Z (13 days ago)
- Last Synced: 2025-01-22T07:12:28.401Z (11 days ago)
- Topics: fortran, linter, python3
- Language: Python
- Homepage:
- Size: 255 KB
- Stars: 31
- Watchers: 6
- Forks: 12
- Open Issues: 6
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Fortran linter
This linter works on a line-by-line basis to enforce some rules regarding the format of Fortran files.
The linter does not ship with any grammar and is solely based on regular expressions. This allows
to easily add new rules, but this implies some limitations.## Installation
There are 2 ways of installing the linter. The recommended one is through pip
pip install fortran-linter
The other way is to clone this repository and install it from the local copy:
git clone https://github.com/cphyc/fortran-syntax.git
cd fortran-syntax
pip install .Please note that depending on your installation, you may have to add `sudo` to the `pip install` line. This is due to the fact that the package is shipped with a script `fortran-linter`. For some installation, the creation of this file may require root access.
## Usage
This tool checks for fortran syntax against a few rules. To print a list of all the warnings for a file, run:
fortran-linter myfile.f90 --syntax-only
To autofix (most) warnings in place, do:
fortran-linter myfile.f90 -i
The original file will be backup'ed into `myfile.f90.orig`. All the safe fixes will be done and stored in the file `myfile.f90`.
For more help, you can type
fortran-linter -h
## Rules
Here is a non-comprehensive set of rules that are enforced:
* Punctuation should be followed by a space, this includes `,`, `;` and `)`.
* Binary operators (`==`, `+`, ...) should be surrounded by spaces
* The following special characters are surrounded by at least one space: `::`, `=`.
* A line should not exceed 120 characters (this is somehow already extreme). The maximum line length can be controlled from the CLI.
* One should use `use mpi` instead of `include "mpif.h"`. Note that this is not fixed by default as it may break codes where `include "mpif.h"` follows and `implicit none` statement.
* Spaces are preferred over tabs, trailing whitespaces are cleaned.
* Warnings are raised if you use `real(8) :: foo`. One should rather use `integer, parameter :: dp = selected_real_kind(15); real(dp) :: foo` or `use iso_fortran_env; real(real64) :: foo`
* `print` statements should look like `print *, "something"`
* `write` statements should look like `write(*, *) "something"`
* Lines should be indented consistently (by default, using an indentation of 4 spaces)
* [FORD](https://forddocs.readthedocs.io/en/latest/) Compatibility: `!!` and `!>` are preserved and treated as comments like `!` with one space after and at least one space before.# TODO list
* [x] ship on pip
* [ ] add more rules (this one will never end)