commit f5bf16be91f0852e9415e71ed1610cfa2484a817 Author: Rob Kelly Date: Fri May 10 16:25:59 2024 -0600 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9aac21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Godot 4+ specific ignores +.godot/ + +# Godot-specific ignores +.import/ +export.cfg +export_presets.cfg + +# Imported translations (automatically generated from CSV files) +*.translation + +# Mono-specific ignores +.mono/ +data_*/ +mono_crash.*.json diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..57e8dda --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Rob Kelly + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a234dff --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# gdLint Plugin + +A bare-bones plugin to run gdLint in Godot 4.x. + +## Setup + +Install [gdscript-toolkit](https://github.com/Scony/godot-gdscript-toolkit). + +If you install the toolkit in a venv, you may want to edit +`run_linter.gd` to set the path to the `gdlint` binary +(e.g. `venv/bin/gdlint`). That way, you won't have to run Godot +through a venv just to use `gdlint`. + +## About + +This is an extremely simple implementation -- the plugin runs `gdlint` +on save, and raises any errors as warnings. + +If you want more full-featured linter integration, check out +[el-falso/gdlinter](https://github.com/el-falso/gdlinter). When I +wrote this plugin, it wasn't being actively maintained. diff --git a/addons/gdlint_plugin/LICENSE b/addons/gdlint_plugin/LICENSE new file mode 100644 index 0000000..57e8dda --- /dev/null +++ b/addons/gdlint_plugin/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Rob Kelly + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/addons/gdlint_plugin/plugin.cfg b/addons/gdlint_plugin/plugin.cfg new file mode 100644 index 0000000..af50175 --- /dev/null +++ b/addons/gdlint_plugin/plugin.cfg @@ -0,0 +1,6 @@ +[plugin] +name="gdLint Plugin" +description="Static code analysis with `gdlint`" +author="Rob Kelly" +version="1.0.0" +script="run_linter.gd" diff --git a/addons/gdlint_plugin/run_linter.gd b/addons/gdlint_plugin/run_linter.gd new file mode 100644 index 0000000..291a11e --- /dev/null +++ b/addons/gdlint_plugin/run_linter.gd @@ -0,0 +1,33 @@ +@tool +class_name GDLintPlugin extends EditorPlugin + +# If you've installed gdlint in a venv, you may want to overwrite this +const GDLINT: String = "gdlint" + + +func _enter_tree() -> void: + assert(not OS.execute(GDLINT, ["-h"]), "Could not find gdLint binary at {0}".format([GDLINT])) + resource_saved.connect(on_save) + + +func _exit_tree() -> void: + resource_saved.disconnect(on_save) + + +func on_save(resource: Resource) -> void: + # Run linting when a script resource is saved + if resource is Script: + var script: Script = resource + var filepath: String = ProjectSettings.globalize_path(resource.resource_path) + + var script_editor = EditorInterface.get_script_editor() + var code_editor: CodeEdit = ( + script_editor.get_current_editor().get_base_editor() + if script_editor.get_current_script() == script + else null + ) + + var gdlint_output: Array[String] = [] + var error: int = OS.execute(GDLINT, [filepath], gdlint_output, true) + if error: + push_warning("gdLint:\n" + gdlint_output[0])