Removes outdated javascript linting from the canvas build
We were using some really outdated tooling for JS linting that caused more problems that it prevented. This pulls it out so we can advance to more modern linting in the future. Test Plan: - Automated tests pass Change-Id: I1bf74c053449ed6374d03475f07ff61ef9227250 Reviewed-on: https://gerrit.instructure.com/93134 Tested-by: Jenkins Reviewed-by: Jon Jensen <jon@instructure.com> Product-Review: Jon Jensen <jon@instructure.com> QA-Review: Jon Jensen <jon@instructure.com>
This commit is contained in:
parent
ec0d45d8d7
commit
cd1f46b421
|
@ -9,64 +9,6 @@ def log_time(name, &block)
|
|||
time
|
||||
end
|
||||
|
||||
def check_syntax(files)
|
||||
quick = ENV["quick"] && ENV["quick"] == "true"
|
||||
puts "--> Checking Syntax...."
|
||||
show_stoppers = []
|
||||
raise "jsl needs to be in your $PATH, download from: javascriptlint.com" if `which jsl`.empty?
|
||||
puts "--> Found jsl..."
|
||||
|
||||
Array(files).each do |js_file|
|
||||
js_file.strip!
|
||||
# only lint things in public/javascripts that are not in /vendor, /compiled, etc.
|
||||
if js_file.match /public\/javascripts\/(?!vendor|compiled|instructure\-ui|i18n.js|translations|old_unsupported_dont_use_react)/
|
||||
file_path = File.join(Rails.root, js_file)
|
||||
|
||||
unless quick
|
||||
# to use this, you need to have jshint installed from npm
|
||||
# (which means you need to have node.js installed)
|
||||
# on osx you can do:
|
||||
# brew install node
|
||||
# npm install jshint
|
||||
unless `which jshint`.empty?
|
||||
puts " --> Checking #{js_file} using JSHint:"
|
||||
js_hint_errors = `jshint #{file_path} --config "#{File.join(Rails.root, '.jshintrc')}"`
|
||||
puts js_hint_errors
|
||||
end
|
||||
|
||||
# Checks for coding style problems using google's js style guide.
|
||||
# Only works if you have gjslint installed.
|
||||
# Download from http://code.google.com/closure/utilities/
|
||||
unless `which gjslint`.empty?
|
||||
puts " --> Checking #{js_file} using gjslint.py:"
|
||||
gjslint_errors = `gjslint --nojsdoc --strict #{js_file}`
|
||||
puts gjslint_errors = gjslint_errors.split("\n").reject{ |l| l.match("Line too long") }.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
jsl_output = `jsl -process "#{file_path}" -nologo -conf "#{File.join(Rails.root, 'config', 'jslint.conf')}"`
|
||||
exit_status = $?.exitstatus
|
||||
if exit_status != 0
|
||||
puts " --> Error checking #{js_file} using jsl:"
|
||||
if jsl_output.match("warning: trailing comma is not legal in ECMA-262 object initializers") || jsl_output.match("extra comma is not recommended in array initializers")
|
||||
exit_status = 2
|
||||
jsl_output << "fatal trailing comma found. Stupid IE!"
|
||||
end
|
||||
if exit_status >= 2
|
||||
show_stoppers << jsl_output
|
||||
end
|
||||
puts jsl_output
|
||||
end
|
||||
end
|
||||
end
|
||||
if show_stoppers.empty?
|
||||
puts " --> No JavaScript errors found using jsl"
|
||||
else
|
||||
raise "FATAL JavaScript errors found using jsl"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
namespace :canvas do
|
||||
desc "Compresses static assets"
|
||||
task :compress_assets do
|
||||
|
@ -86,30 +28,12 @@ namespace :canvas do
|
|||
puts "Compressed #{processed} assets, #{before_bytes} -> #{after_bytes} bytes (#{"%.0f" % ((before_bytes.to_f - after_bytes.to_f) / before_bytes * 100)}% reduction)"
|
||||
end
|
||||
|
||||
task :check_syntax => "canvas:check_syntax:all"
|
||||
namespace :check_syntax do
|
||||
desc "Checks all js files that are staged for commiting to git for syntax errors. Make your .git/hooks/pre-commit look like: rake canvas:check_syntax:changed quick=true to not allow committing js with syntax errors"
|
||||
task :changed do
|
||||
files = `git diff-index --name-only --cached HEAD -- | grep '\.js$'`
|
||||
check_syntax(files)
|
||||
end
|
||||
|
||||
desc "Checks all js files for sytax errors."
|
||||
task :all do
|
||||
#bundles = YAML.load(ERB.new(File.read('config/assets.yml')).result)['javascripts']
|
||||
files = (Dir.glob('./public/javascripts/*.js')).
|
||||
reject{ |file| file =~ /\A\.\/public\/javascripts\/(i18n.js|translations\/)/ }
|
||||
|
||||
check_syntax(files)
|
||||
end
|
||||
end
|
||||
|
||||
desc "Compile javascript and css assets."
|
||||
task :compile_assets, :generate_documentation, :check_syntax, :compile_styleguide, :build_js do |t, args|
|
||||
# :check_syntax is currently a dummy argument that isn't used.
|
||||
args.with_defaults(:generate_documentation => true, :check_syntax => false, :compile_styleguide => true, :build_js => true)
|
||||
truthy_values = [true, 'true', '1']
|
||||
generate_documentation = truthy_values.include?(args[:generate_documentation])
|
||||
check_syntax = truthy_values.include?(args[:check_syntax])
|
||||
compile_styleguide = truthy_values.include?(args[:compile_styleguide])
|
||||
build_js = truthy_values.include?(args[:build_js])
|
||||
|
||||
|
@ -158,12 +82,6 @@ namespace :canvas do
|
|||
}
|
||||
end
|
||||
|
||||
if check_syntax
|
||||
tasks["check JavaScript syntax"] = -> {
|
||||
Rake::Task['canvas:check_syntax'].invoke
|
||||
}
|
||||
end
|
||||
|
||||
if generate_documentation
|
||||
tasks["Generate documentation [yardoc]"] = -> {
|
||||
Rake::Task['doc:api'].invoke
|
||||
|
@ -194,11 +112,6 @@ namespace :canvas do
|
|||
Rake::Task['i18n:check'].invoke
|
||||
end
|
||||
|
||||
threads << Thread.new do
|
||||
puts "--> Check syntax"
|
||||
Rake::Task['canvas:check_syntax'].invoke
|
||||
end
|
||||
|
||||
threads << Thread.new do
|
||||
puts "--> Generating API documentation"
|
||||
Rake::Task['doc:api'].invoke
|
||||
|
|
Loading…
Reference in New Issue