Skip to content

Commit 50e4065

Browse files
committed
initial commit
1 parent f8cbd75 commit 50e4065

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributor Code of Conduct
2+
3+
[Don't be a jerk.](https://meta.wikimedia.org/wiki/Don%27t_be_a_jerk)

LICENCE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2+
3+
Copyright (C) 2024 Gilles Roustan <[email protected]>
4+
5+
Everyone is permitted to copy and distribute verbatim or modified
6+
copies of this license document, and changing it is allowed as long
7+
as the name is changed.
8+
9+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
10+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
11+
12+
0. You just DO WHAT THE FUCK YOU WANT TO.
13+

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
# none-ls-php.nvim
2+
23
Native PHP diagnostic plugin for none-ls.nvim
4+
5+
Since this diagnostic will be deprecated from [none-ls.nvim](https://github.com/nvimtools/none-ls.nvim)
6+
(see [this issue](https://github.com/nvimtools/none-ls.nvim/issues/58)) because a LSP alternative is available,
7+
this repository allows to keep using native php linter with none-ls.nvim.
8+
9+
**Note:** This plugin is not intended to be used alone, it is a dependency of none-ls.nvim.
10+
11+
## 📦 Installation
12+
13+
This should be used as a dependency of **none-ls.nvim**.
14+
15+
### [lazy.nvim](https://github.com/folke/lazy.nvim)
16+
17+
```lua
18+
{
19+
{
20+
"nvimtools/none-ls.nvim",
21+
config = function()
22+
require("null-ls").register(require("none-ls-php.diagnostics.php"))
23+
end,
24+
dependencies = {
25+
"gbprod/none-ls-php.nvim",
26+
},
27+
},
28+
}
29+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
-- Tested using PHP 7.x and PHP 8.x.
2+
local h = require("null-ls.helpers")
3+
local methods = require("null-ls.methods")
4+
5+
local DIAGNOSTICS = methods.internal.DIAGNOSTICS
6+
7+
return h.make_builtin({
8+
name = "php",
9+
meta = {
10+
url = "https://www.php.net/",
11+
description = "Uses the php command-line tool's built in `-l` flag to check for syntax errors.",
12+
},
13+
method = DIAGNOSTICS,
14+
filetypes = { "php" },
15+
generator_opts = {
16+
command = "php",
17+
-- Send file to stdin otherwise checking is only done when the file is saved.
18+
to_stdin = true,
19+
to_temp_file = false,
20+
-- -d display_errors=STDERR ensures errors are reported to stderr.
21+
-- -d log_errors=Off Disables logging of errors.
22+
--
23+
-- Without these, a setting in php.ini can turn off error reporting, or
24+
-- change where errors are reported.
25+
args = { "-l", "-d", "display_errors=STDERR", "-d", " log_errors=Off" },
26+
from_stderr = true,
27+
format = "line",
28+
check_exit_code = function(code)
29+
-- Code 0 means no syntax errors.
30+
-- Code 255 means syntax errors.
31+
-- Other codes mean something went wrong.
32+
return code == 0 or code == 255
33+
end,
34+
on_output = h.diagnostics.from_patterns({
35+
{
36+
-- Example of an error when checking a file:
37+
-- Parse error: syntax error, unexpected '$appends' (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST) in app/Config.php on line 16
38+
39+
-- Example of an error when checking stdin:
40+
-- Parse error: syntax error, unexpected token "=>", expecting "," or ";" in Standard input code on line 21
41+
42+
-- This pattern should match both.
43+
pattern = [[Parse error: (.*) in (.*) on line (%d+)]],
44+
groups = { "message", "junk", "row" },
45+
overrides = {
46+
diagnostic = { severity = h.diagnostics.severities["error"] },
47+
offsets = { col = 1, end_col = 1 },
48+
},
49+
},
50+
}),
51+
},
52+
factory = h.generator_factory,
53+
})

0 commit comments

Comments
 (0)