https://github.com/xuhdev/editorconfig-cf
A tool to check and fix coding style according to .editorconfig file. It passes the fixing tasks to specific language beautifiers.
https://github.com/xuhdev/editorconfig-cf
Last synced: 8 months ago
JSON representation
A tool to check and fix coding style according to .editorconfig file. It passes the fixing tasks to specific language beautifiers.
- Host: GitHub
- URL: https://github.com/xuhdev/editorconfig-cf
- Owner: xuhdev
- License: lgpl-3.0
- Created: 2014-03-13T08:24:54.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2022-01-13T17:19:32.000Z (over 4 years ago)
- Last Synced: 2025-02-01T15:22:52.501Z (over 1 year ago)
- Language: Python
- Homepage: http://editorconfig.org
- Size: 191 KB
- Stars: 8
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# EditorConfig-cf -- EditorConfig Checker and Formatter
This python program uses the rule given in [EditorConfig][] files to check and fix your coding style.
It is still under development, but your contribution is highly appreciated, since I do not use all languages!
## Usage
python /path/to/editorconfig_cf.py [check|format] [file1] [file2] [file3] ...
where `[file1]`, `[file2]`, `[file3]`, ... are the source files you want to check or format.
## How It Works
This script does not touch your code directly; instead, it calls language specific beautifier to check and fix.
When given a file, it first see what type this file is according to its extension. After determining the type of the
source file, EditorConfig-cf tries to call the corresponding beautifiers it knows. If a beautifier is found to be
usable, EditorConfig-cf calls the beautifier to check or fix the source code and outputs the fixed code into a file with
`.ecfmt` extension.
For example, when dealing with a C source file named `main.c`, EditorConfig-cf tries to call [uncrustify][]. If
uncrustify is available, it will be used to format this C source file, and write the output into `main.c.ecfmt`.
## Contribution
### How Can I Add Beautifier for My Favorite language?
The framework is already there, what you need is to add your own handling function to handle this type of file with the
beautifier in the `handling` directory, then insert a few lines to tell some information about the beautifier (such as name,
for what language).
Here are the details.
#### Add Handling Function for Your Beautifier
Create a new file for your beautifier in the `handling` directory. You need to define a function with the following prototype:
handling(executable, input_file_path, output_file_path, editorconfig_properties)
Where `executable` is the `executable` of the beautifier to be passed in, `input_file_path` is the file needs to be
formatted, `output_file_path` is where the formatted file should be written into, `editorconfig_properties` is the
output of EditorConfig library passed in (see [EditorConfig Python Core Document][] for what this variable is), `c_or_f`
shows whether this is checking ('c') or formatting ('f'). You need to fill this function so that the framework can call
this function to handle the specific type of file with the specific beautifier. You will tell the location of this
function later.
#### Add Meta Information of Beautifier
Edit `editorconfig_cf.py`, check the function `get_language_info` and `get_beautifier_info`. Check the existing
beautifier and insert meta info of the beautifier you are going to add.
#### Add Tests in the `tests` Directory
This should be fairly straightforward. Simply refer the other tests and modify it.
### Contribution License
If you added any new files, remember you need to add a license header as the other files do. If you code is less than 50
effective lines, you can simply copy a header from another file and copyright it under my name. If you do not want to
copyright the code under my name, I will not be against copyright under your name. I encourage you to license under
LGPLv3+, but at least your license must be compatible with the other part of the project, that is, a permissive license
(Apache v2, BSD, MIT, etc.) or LGPLv3+. LGPLv2 or GPL are not acceptable.
## License
Copyright (C) Hong Xu
Unless otherwise stated, most files are licensed under [GNU Lesser General Public License Version 3][] or later. See the
header of each file for license details.
[uncrustify]: http://uncrustify.sourceforge.net
[EditorConfig]: http://editorconfig
[EditorConfig Python Core Document]: http://pydocs.editorconfig.org/en/latest/usage.html
[GNU Lesser General Public License Version 3]: https://www.gnu.org/licenses/lgpl.html