vis-lint

vis plugin for linting code
git clone anongit@rnpnr.xyz:vis-lint.git
Log | Files | Refs | Feed | README | LICENSE

README.md (2453B)


      1 # vis-lint
      2 
      3 Lint the currently open file in [Vis](https://github.com/martanne/vis)
      4 and display the output in the message window.
      5 
      6 ## Installation
      7 
      8 Clone the repo to `$VIS_PATH/plugins` and then its sufficient to include
      9 the following in your `visrc.lua`:
     10 
     11 	require("plugins/vis-lint")
     12 
     13 See [Plugins](https://github.com/martanne/vis/wiki/Plugins) on the Vis
     14 wiki for further details.
     15 
     16 ## Usage
     17 
     18 The following functions and commands are exported:
     19 
     20 | Name                 | Description                                      |
     21 |----------------------|--------------------------------------------------|
     22 | `lint`               | Run to lint the current file (range if selected) |
     23 | `fix`                | Run to fix the current file (range if selected)  |
     24 | `.lint(file, range)` | `lint` command accessible from Lua               |
     25 | `.fix(file, range)`  | `fix` command accessible from Lua                |
     26 
     27 For example type the following into the Vis command prompt:
     28 
     29 	:lint
     30 
     31 ## Configuration
     32 
     33 ### Adding A Tool
     34 
     35 Additional tools for fixing and linting can be added as follows:
     36 
     37 	local lint = require("plugins/vis-lint")
     38 	table.insert(lint.linters["python"], "pylint --from-stdin stdin_from_vis")
     39 	table.insert(lint.linters["python"], "mypy /dev/stdin")
     40 
     41 #### Tools must read from `stdin` and output to `stdout`!
     42 
     43 Some programs, like the above examples, may need some non standard flags.
     44 You can also try using `-` or `/dev/stdin` as the input parameter.
     45 
     46 ### Overriding The Defaults
     47 
     48 The defaults can be also be overridden:
     49 
     50 	lint.fixers["lua"] = { "cat" }
     51 
     52 Note that an equivalent in this case is just:
     53 
     54 	lint.fixers["lua"] = {}
     55 
     56 ### Adding New Filetypes
     57 
     58 A new filetype can be added as follows (`awkfix` is a hypothetical
     59 `awk` fixer):
     60 
     61 	lint.fixers["awk"] = { "awkfix" }
     62 
     63 Note: if a default doesn't exist feel free to submit a patch adding it!
     64 
     65 ### Running Fixers Before Writing
     66 
     67 The fixers can be run before saving a file using Vis' events:
     68 
     69 	vis.events.subscribe(vis.events.FILE_SAVE_PRE, lint.fix)
     70 
     71 Note that if any fixer fails the file won't save (unless `:w!` was used).
     72 
     73 ### Silencing Logging Or Logging To File
     74 
     75 The logging function is stored as a configuration variable and can be
     76 modified as follows:
     77 
     78 	lint.logger = function(str, level)
     79 		if level == lint.log.INFO then
     80 			vis:info(str)
     81 		else
     82 			local fp = io.open("log.txt", "*a")
     83 			fp:write(str .. "\n")
     84 			fp:close()
     85 		end
     86 	end
     87 
     88 The sent message levels are `INFO`, `OUTPUT`, and `ERROR`.