Skip to content

Commit

Permalink
Merge pull request #5 from el-falso/development
Browse files Browse the repository at this point in the history
bump version to 2.0
  • Loading branch information
el-falso authored Mar 20, 2024
2 parents 32686c3 + aeaf819 commit 58fbefd
Show file tree
Hide file tree
Showing 16 changed files with 819 additions and 133 deletions.
44 changes: 44 additions & 0 deletions addons/gdLinter/Settings/ignore.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class_name GDLinterIgnore
extends Resource

@export_group("Name Checks")
@export var _function_name: bool = false
@export var _class_name: bool = false
@export var _sub_class_name: bool = false
@export var _signal_name: bool = false
@export var _class_variable_name: bool = false
@export var _class_load_variable_name: bool = false
@export var _function_variable_name: bool = false
@export var _function_preload_variable_name: bool = false
@export var _function_argument_name: bool = false
@export var _loop_variable_name: bool = false
@export var _enum_name: bool = false
@export var _enum_element_name: bool = false
@export var _constant_name: bool = false
@export var _load_constant_name: bool = false

@export_group("Basic Checks")
@export var _duplicated_load: bool = false
@export var _expression_not_assigned: bool = false
@export var _unnecessary_pass: bool = false
@export var _unused_argument: bool = false
@export var _comparison_with_itself: bool = false

@export_group("Class Checks")
@export var _private_method_call: bool = false
@export var _class_definitions_order: bool = false

@export_group("Design Checks")
@export var _max_public_methods: bool = false
@export var _function_arguments_number: bool = false

@export_group("Format Checks")
@export var _max_file_lines: bool = false
@export var _trailing_whitespace: bool = false
@export var _max_line_length: bool = false
@export var _mixed_tabs_and_spaces: bool = false

@export_group("Misc Checks")
@export var _no_elif_return: bool = false
@export var _no_else_return: bool = false

35 changes: 35 additions & 0 deletions addons/gdLinter/Settings/ignore.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[gd_resource type="Resource" script_class="GDLinterIgnore" load_steps=2 format=3 uid="uid://6ip8eigu30by"]

[ext_resource type="Script" path="res://addons/gdLinter/Settings/ignore.gd" id="1_8j37n"]

[resource]
script = ExtResource("1_8j37n")
_function_name = false
_class_name = false
_sub_class_name = false
_signal_name = false
_class_variable_name = false
_class_load_variable_name = false
_function_variable_name = false
_function_preload_variable_name = false
_function_argument_name = false
_loop_variable_name = false
_enum_name = false
_enum_element_name = false
_constant_name = false
_load_constant_name = false
_duplicated_load = false
_expression_not_assigned = false
_unnecessary_pass = false
_unused_argument = false
_comparison_with_itself = false
_private_method_call = false
_class_definitions_order = false
_max_public_methods = false
_function_arguments_number = false
_max_file_lines = false
_trailing_whitespace = false
_max_line_length = false
_mixed_tabs_and_spaces = false
_no_elif_return = false
_no_else_return = false
39 changes: 39 additions & 0 deletions addons/gdLinter/UI/Basic.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@tool
extends MarginContainer

var _owner: GDLinterIgnoreWindow = owner

@onready var duplicated_load: CheckBox = %DuplicatedLoad
@onready var expression_not_assigned: CheckBox = %ExpressionNotAssigned
@onready var unnecessary_pass: CheckBox = %UnnecessaryPass
@onready var unused_argument: CheckBox = %UnusedArgument
@onready var comparision_with_itself: CheckBox = %ComparisionWithItself


func init() -> void:
_owner = owner
duplicated_load.button_pressed = _owner.ignore.get("_duplicated_load")
expression_not_assigned.button_pressed = _owner.ignore.get("_expression_not_assigned")
unnecessary_pass.button_pressed = _owner.ignore.get("_unnecessary_pass")
unused_argument.button_pressed = _owner.ignore.get("_unused_argument")
comparision_with_itself.button_pressed = _owner.ignore.get("_comparison_with_itself")


func _on_duplicated_load_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_duplicated_load", toggled_on)


func _on_expression_not_assigned_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_expression_not_assigned", toggled_on)


func _on_unnecessary_pass_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_unnecessary_pass", toggled_on)


func _on_unused_argument_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_unused_argument", toggled_on)


func _on_comparision_with_itself_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_comparison_with_itself", toggled_on)
21 changes: 21 additions & 0 deletions addons/gdLinter/UI/Class.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@tool
extends MarginContainer

var _owner: GDLinterIgnoreWindow = owner

@onready var private_method_call: CheckBox = %PrivateMethodCall
@onready var class_definition_order: CheckBox = %ClassDefinitionOrder


func init() -> void:
_owner = owner
private_method_call.button_pressed = _owner.ignore.get("_private_method_call")
class_definition_order.button_pressed = _owner.ignore.get("_class_definitions_order")


func _on_private_method_call_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_private_method_call", toggled_on)


func _on_class_definition_order_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_class_definitions_order", toggled_on)
21 changes: 21 additions & 0 deletions addons/gdLinter/UI/Design.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@tool
extends MarginContainer

var _owner: GDLinterIgnoreWindow = owner

@onready var max_public_methods: CheckBox = %MaxPublicMethods
@onready var function_argument_number: CheckBox = %FunctionArgumentNumber


func init() -> void:
_owner = owner
max_public_methods.button_pressed = _owner.ignore.get("_max_public_methods")
function_argument_number.button_pressed = _owner.ignore.get("_function_arguments_number")


func _on_max_public_methods_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_max_public_methods", toggled_on)


func _on_function_argument_number_toggled(toggled_on: bool) -> void:
_owner.ignore.set("_function_arguments_number", toggled_on)
103 changes: 90 additions & 13 deletions addons/gdLinter/UI/Dock.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,100 @@
class_name GDLinterDock
extends Control

const ERROR_BUTTON = preload("res://addons/gdLinter/UI/ErrorButton.tscn")

var gd_linter: GDLinter
var error_descriptions := preload("res://addons/gdLinter/error_descriptions.gd").new()
var script_text_editor: ScriptEditorBase
var color_error: Color = EditorInterface.get_editor_settings()\
.get_setting("text_editor/theme/highlighting/comment_markers/critical_color")

var num_problems: int = 0
var num_ignored_problems: int = 0

var _ignore: GDLinterIgnore = preload("res://addons/gdLinter/Settings/ignore.tres")

@onready var file: Label = %File
@onready var label: Label = %Label
@onready var error_holder: VBoxContainer = %ErrorHolder
@onready var problems_num: Label = %ProblemsNum
@onready var ignored_problems_num: Label = %IgnoredProblemsNum
@onready var version: Label = %Version
@onready var tree: Tree = %Tree
@onready var gd_linter_ignore_window: GDLinterIgnoreWindow = $GdLinterIgnoreWindow


func _ready() -> void:
gd_linter_ignore_window.ignore = _ignore
gd_linter_ignore_window.dock_ui = self
tree.add_theme_color_override("font_color", color_error)
tree.set_column_title(0, "Line")
tree.set_column_title(1, "Error")
tree.set_column_title_alignment(0, HORIZONTAL_ALIGNMENT_LEFT)
tree.set_column_title_alignment(1, HORIZONTAL_ALIGNMENT_LEFT)
tree.set_column_custom_minimum_width(0, 75)
tree.set_column_custom_minimum_width(1, 0)
tree.set_column_expand(0, false)
tree.set_column_expand(1, true)
tree.set_column_clip_content(0, false)
tree.set_column_clip_content(1, true)
tree.set_column_expand_ratio(0, 4)
tree.item_activated.connect(_on_item_activated)

func reset_problem_num() -> void:
num_problems = 0
num_ignored_problems = 0


func create_item(line: int, name: String) -> void:
var regex = RegEx.new()
regex.compile("(?<=\\()[^\\)]+")
var result := regex.search_all(name)
var error_type := result[-1].strings[0]
if _ignore.get(str_dash_to_underscore(error_type)):
num_ignored_problems += 1
return

var item := tree.create_item()
item.set_text(0, str(line))
item.set_text(1, name)
item.set_metadata(0, line)

if error_descriptions.error.has(error_type):
item.set_tooltip_text(1, error_descriptions.error[error_type])
num_problems += 1


func set_problems_label(number: int) -> void:
problems_num.text = str(number)


func set_ignored_problems_label(number: int) -> void:
ignored_problems_num.text = str(number)

func clear_items() -> void:
reset_problem_num()
tree.clear()
tree.create_item()


func _on_item_activated() -> void:
var selected: TreeItem = tree.get_selected()
var line := selected.get_metadata(0)

EditorInterface.edit_script(load(file.text), line)

if not EditorInterface.get_editor_settings().get("text_editor/external/use_external_editor"):
EditorInterface.set_main_screen_editor("Script")


func str_dash_to_underscore(string: String) -> String:
return "_" + string.replace("-", "_")


func is_error_ignored(name: String) -> bool:
var regex = RegEx.new()
regex.compile("(?<=\\()[^\\)]+")
var result := regex.search_all(name)
var error_type := result[-1].strings[0]
return _ignore.get(str_dash_to_underscore(error_type))

func create_error(name: String) -> Button:
var error: Button = ERROR_BUTTON.instantiate()
error.text = name
error_holder.add_child(error)
return error

func delete_errors() -> void:
var children := error_holder.get_children()
for child: Button in children:
child.queue_free()
func _on_button_pressed() -> void:
gd_linter_ignore_window.popup()
56 changes: 50 additions & 6 deletions addons/gdLinter/UI/Dock.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://d1eqlqvotirg1"]
[gd_scene load_steps=3 format=3 uid="uid://d1eqlqvotirg1"]

[ext_resource type="Script" path="res://addons/gdLinter/UI/Dock.gd" id="1_u5r3b"]
[ext_resource type="PackedScene" uid="uid://cgk7hjif0ujw1" path="res://addons/gdLinter/UI/GDLinterIgnoreWindow.tscn" id="3_ib5aw"]

[node name="Dock" type="Control"]
layout_mode = 3
Expand All @@ -25,7 +26,7 @@ layout_mode = 2
[node name="RichTextLabel" type="RichTextLabel" parent="VBoxContainer/Header"]
layout_mode = 2
bbcode_enabled = true
text = "[center]GDLint Plugin 1.0.1[/center]"
text = "[center]GDLint Plugin 2.0.0[/center]"
fit_content = true

[node name="LintedFile" type="PanelContainer" parent="VBoxContainer"]
Expand All @@ -42,26 +43,69 @@ text = "Currently linted file:"
unique_name_in_owner = true
layout_mode = 2

[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
[node name="MiddleContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 20.0

[node name="ErrorHolder" type="VBoxContainer" parent="VBoxContainer/ScrollContainer"]
[node name="Tree" type="Tree" parent="VBoxContainer/MiddleContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
focus_mode = 0
theme_override_colors/font_color = Color(0.77, 0.35, 0.35, 1)
theme_override_constants/v_separation = 0
columns = 2
column_titles_visible = true
hide_folding = true
hide_root = true
select_mode = 1
scroll_horizontal_enabled = false

[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/MiddleContainer"]
layout_mode = 2

[node name="Button" type="Button" parent="VBoxContainer/MiddleContainer/VBoxContainer"]
layout_mode = 2
text = "Ignore
Settings"

[node name="Statusbar" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 10

[node name="Label" type="Label" parent="VBoxContainer/Statusbar"]
[node name="ProblemsContainer" type="HBoxContainer" parent="VBoxContainer/Statusbar"]
layout_mode = 2
theme_override_constants/separation = 0

[node name="ProblemsNum" type="Label" parent="VBoxContainer/Statusbar/ProblemsContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text = "0"

[node name="ProblemsLbl" type="Label" parent="VBoxContainer/Statusbar/ProblemsContainer"]
layout_mode = 2
text = "problems found"

[node name="VSeparator" type="VSeparator" parent="VBoxContainer/Statusbar/ProblemsContainer"]
layout_mode = 2

[node name="IgnoredProblemsNum" type="Label" parent="VBoxContainer/Statusbar/ProblemsContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "0"

[node name="IgnoredProblemsLbl" type="Label" parent="VBoxContainer/Statusbar/ProblemsContainer"]
layout_mode = 2
text = "problems ignored"

[node name="Version" type="Label" parent="VBoxContainer/Statusbar"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
horizontal_alignment = 2

[node name="GdLinterIgnoreWindow" parent="." instance=ExtResource("3_ib5aw")]
dialog_text = ""

[connection signal="pressed" from="VBoxContainer/MiddleContainer/VBoxContainer/Button" to="." method="_on_button_pressed"]
Loading

0 comments on commit 58fbefd

Please sign in to comment.