summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2019-05-22 06:05:04 +0000
committerAsh McKenzie <amckenzie@gitlab.com>2019-05-22 06:05:04 +0000
commitc342c07899ef6637eef7c1df2534f0c5ea67d7bd (patch)
tree02bb4da366341993965c875f77b141535520082b /lib
parenta6e2ec0d954a14bd0ff4b1f37b3f6889eea28fde (diff)
parent27381e22a92453b23f1ed75406970b37d926f1ec (diff)
downloadgitlab-ce-c342c07899ef6637eef7c1df2534f0c5ea67d7bd.tar.gz
Merge branch 'sh-fix-linter-registry-haml-try2' into 'master'
Fix uninitialized constant with HamlLint::LinterRegistry Closes #62125 See merge request gitlab-org/gitlab-ce!28578
Diffstat (limited to 'lib')
-rw-r--r--lib/haml_lint/inline_javascript.rb25
-rw-r--r--lib/haml_lint/linter/no_plain_nodes.rb84
-rw-r--r--lib/tasks/haml-lint.rake2
3 files changed, 1 insertions, 110 deletions
diff --git a/lib/haml_lint/inline_javascript.rb b/lib/haml_lint/inline_javascript.rb
deleted file mode 100644
index 1b17162f71d..00000000000
--- a/lib/haml_lint/inline_javascript.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-unless Rails.env.production?
- require_dependency 'haml_lint/haml_visitor'
- require_dependency 'haml_lint/linter'
- require_dependency 'haml_lint/linter_registry'
-
- module HamlLint
- class Linter::InlineJavaScript < Linter
- include LinterRegistry
-
- def visit_filter(node)
- return unless node.filter_type == 'javascript'
-
- record_lint(node, 'Inline JavaScript is discouraged (https://docs.gitlab.com/ee/development/gotchas.html#do-not-use-inline-javascript-in-views)')
- end
-
- def visit_tag(node)
- return unless node.tag_name == 'script'
-
- record_lint(node, 'Inline JavaScript is discouraged (https://docs.gitlab.com/ee/development/gotchas.html#do-not-use-inline-javascript-in-views)')
- end
- end
- end
-end
diff --git a/lib/haml_lint/linter/no_plain_nodes.rb b/lib/haml_lint/linter/no_plain_nodes.rb
deleted file mode 100644
index d5cea0d07cf..00000000000
--- a/lib/haml_lint/linter/no_plain_nodes.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-# frozen_string_literal: true
-
-require 'active_support/core_ext/array/grouping'
-
-module HamlLint
- class Linter
- class NoPlainNodes < Linter
- include LinterRegistry
-
- def visit_tag(node)
- if inline_plain_node?(node)
- check_inline(node)
- elsif !node.script.empty?
- check_script(node)
- else
- check(node)
- end
- end
-
- private
-
- def check(node)
- text_in_node(node).each { |string| record(node, string) }
- end
-
- def check_inline(node)
- text = inline_text(node)
- record(node, text) unless text.empty?
- end
-
- def check_script(node)
- text = inline_text(node)
- record(node, text) unless text.start_with?('=') || text.empty?
- end
-
- # Build an array of all strings in child text nodes.
- # non text nodes are nil, where we'll split the sentences.
- def text_in_node(node)
- texts = node.children.map do |child|
- child.text.strip if text_node?(child)
- end
-
- texts.split(nil).map { |sentence| sentence.join(' ') unless sentence.empty? }.compact
- end
-
- # Removes a node's attributes and tag from the source code,
- # returning the inline text of a node.
- def inline_text(node)
- text = node.source_code.gsub("%#{node.tag_name}", '')
-
- attributes = node.attributes_source.map(&:last)
- attributes.each { |attribute| text = text.gsub(attribute, '') }
-
- text.strip
- end
-
- def record(node, string)
- record_lint(node, message(string))
- end
-
- def message(string)
- "`#{string}` is a plain node. Please use an i18n method like `#{fixed(string)}`"
- end
-
- def fixed(string)
- "= _('#{string}')"
- end
-
- def inline_plain_node?(node)
- node.children.empty? && node.script.empty?
- end
-
- def plain_node?(node)
- node.is_a?(::HamlLint::Tree::PlainNode)
- end
-
- def text_node?(node)
- return false unless plain_node?(node)
-
- !node.text.empty?
- end
- end
- end
-end
diff --git a/lib/tasks/haml-lint.rake b/lib/tasks/haml-lint.rake
index 786efd14b1a..305e15d69d5 100644
--- a/lib/tasks/haml-lint.rake
+++ b/lib/tasks/haml-lint.rake
@@ -1,6 +1,6 @@
unless Rails.env.production?
require 'haml_lint/rake_task'
- require 'haml_lint/inline_javascript'
+ require Rails.root.join('haml_lint/inline_javascript')
# Workaround for warnings from parser/current
# Keep it even if it no longer emits any warnings,