Add scss_lint tasks scss_lint:xml and scss_lint:html that support source code analysis of SCSS files.
Project: http://git-wip-us.apache.org/repos/asf/buildr/repo Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/44082045 Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/44082045 Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/44082045 Branch: refs/heads/master Commit: 44082045e1781983ddf83764a7ce6e1977c6e557 Parents: 7ed3fac Author: Peter Donald <[email protected]> Authored: Sat May 24 13:33:54 2014 +1000 Committer: Peter Donald <[email protected]> Committed: Sat May 24 13:56:07 2014 +1000 ---------------------------------------------------------------------- CHANGELOG | 2 + addon/buildr/scss_link.rake | 195 +++++++++++++++++++++++++++++++++ addon/buildr/scss_lint-report.xsl | 79 +++++++++++++ doc/more_stuff.textile | 31 ++++++ 4 files changed, 307 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/buildr/blob/44082045/CHANGELOG ---------------------------------------------------------------------- diff --git a/CHANGELOG b/CHANGELOG index 772742d..22c84c3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ 1.4.17 (Pending) * Fixed: Fix the vcs detection in IDEA addon for 1.8.6 (!) versions of ruby by reordering blocks. +* Added: Add scss_lint tasks scss_lint:xml and scss_lint:html that + support source code analysis of SCSS files. * Added: Import 'buildr/custom_pom' addon to make it easier to build POMs for projects publishing to Maven Central. * Added: Add flag to allow non portable extensions in wsgen addon. http://git-wip-us.apache.org/repos/asf/buildr/blob/44082045/addon/buildr/scss_link.rake ---------------------------------------------------------------------- diff --git a/addon/buildr/scss_link.rake b/addon/buildr/scss_link.rake new file mode 100644 index 0000000..bd79994 --- /dev/null +++ b/addon/buildr/scss_link.rake @@ -0,0 +1,195 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with this +# work for additional information regarding copyright ownership. The ASF +# licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +module Buildr + # Provides the <code>scss_lint:html</code> and <code>scss_lint:xml</code> tasks. + # Require explicitly using <code>require "buildr/scss_lint"</code>. + module ScssLint + class << self + + def scss_lint(output_file, source_paths, options = {}) + args = [] + if ENV['BUNDLE_GEMFILE'] + args << 'bundle' + args << 'exec' + end + args << 'scss-lint' + if options[:configuration_file] + args << '--config' + args << options[:configuration_file] + end + if options[:file_excludes] + args << '--exclude' + args << options[:file_excludes].join(',') + end + if options[:formatter] + args << '--format' + args << options[:formatter] + end + if options[:linter_includes] && !options[:linter_includes].empty? + args << '--include-linter' + args << options[:linter_includes].join(',') + end + if options[:linter_excludes] && !options[:linter_excludes].empty? + args << '--exclude-linter' + args << options[:linter_excludes].join(',') + end + + source_paths.each do |source_path| + args << source_path + end + + mkdir_p File.dirname(output_file) + File.open(output_file, 'wb') do |f| + f.write `#{args.join(' ')}` + end + end + end + + class Config + def enabled? + File.exist?(self.configuration_file) + end + + def html_enabled? + File.exist?(self.style_file) + end + + attr_writer :config_directory + + def config_directory + @config_directory || project._(:source, :main, :etc, :scss_lint) + end + + attr_writer :report_dir + + def report_dir + @report_dir || project._(:reports, :scss_lint) + end + + attr_writer :file_excludes + + def file_excludes + @file_excludes ||= [] + end + + attr_writer :linter_includes + + def linter_includes + @linter_includes ||= [] + end + + attr_writer :linter_excludes + + def linter_excludes + @linter_excludes ||= [] + end + + attr_writer :configuration_file + + def configuration_file + @configuration_file || "#{self.config_directory}/checks.yml" + end + + attr_writer :format + + def format + @format || 'XML' + end + + attr_writer :xml_output_file + + def xml_output_file + @xml_output_file || "#{self.report_dir}/scss_lint.xml" + end + + attr_writer :html_output_file + + def html_output_file + @html_output_file || "#{self.report_dir}/scss_lint.html" + end + + attr_writer :style_file + + def style_file + unless @style_file + project_xsl = "#{self.config_directory}/scss_lint-report.xsl" + if File.exist?(project_xsl) + @style_file = project_xsl + else + @style_file = "#{File.dirname(__FILE__)}/scss_lint-report.xsl" + end + end + @style_file + end + + def source_paths + @source_paths ||= [self.project._(:source, :main, :webapp, :sass)] + end + + protected + + def initialize(project) + @project = project + end + + attr_reader :project + + end + + module ProjectExtension + include Extension + + def scss_lint + @scss_lint ||= Buildr::ScssLint::Config.new(project) + end + + after_define do |project| + if project.scss_lint.enabled? + desc "Generate scss-lint xml report." + project.task("scss_lint:xml") do + puts "ScssLint: Analyzing source code..." + Buildr::ScssLint.scss_lint(project.scss_lint.xml_output_file, + project.scss_lint.source_paths.flatten.compact, + :formatter => project.scss_lint.format, + :configuration_file => project.scss_lint.configuration_file, + :file_excludes => project.scss_lint.file_excludes, + :linter_includes => project.scss_lint.linter_includes, + :linter_excludes => project.scss_lint.linter_excludes) + end + + if project.scss_lint.html_enabled? + xml_task = project.task("scss_lint:xml") + desc "Generate scss_lint html report." + project.task("scss_lint:html" => xml_task) do + puts "ScssLint: Generating report" + mkdir_p File.dirname(project.scss_lint.html_output_file) + Buildr.ant "scss_lint" do |ant| + ant.xslt :in => project.scss_lint.xml_output_file, + :out => project.scss_lint.html_output_file, + :style => project.scss_lint.style_file + end + end + + end + end + end + end + end +end + +class Buildr::Project + include Buildr::ScssLint::ProjectExtension +end http://git-wip-us.apache.org/repos/asf/buildr/blob/44082045/addon/buildr/scss_lint-report.xsl ---------------------------------------------------------------------- diff --git a/addon/buildr/scss_lint-report.xsl b/addon/buildr/scss_lint-report.xsl new file mode 100644 index 0000000..b378207 --- /dev/null +++ b/addon/buildr/scss_lint-report.xsl @@ -0,0 +1,79 @@ +<?xml version="1.0"?> + +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + + <xsl:template match="/"> + <html> + <head> + <title>ScssLint Violations</title> + </head> + <body bgcolor="#FFFFEF"> + <p> + <b>Coding Style Check Results</b> + </p> + <table border="1" cellspacing="0" cellpadding="2"> + <tr bgcolor="#CC9966"> + <th colspan="2"> + <b>Summary</b> + </th> + </tr> + <tr bgcolor="#F3F3E1"> + <td>Files with errors</td> + <td> + <xsl:number level="any" value="count(descendant::file)"/> + </td> + </tr> + <tr bgcolor="#CCF3D0"> + <td>Total errors</td> + <td> + <xsl:number level="any" value="count(descendant::issue)"/> + </td> + </tr> + </table> + <hr align="left" width="95%" size="1"/> + <p>The following are violations of the ScssLint Rules:</p> + <p/> + <xsl:apply-templates/> + </body> + </html> + </xsl:template> + + <xsl:template match="file[issue]"> + <table bgcolor="#AFFFFF" width="95%" border="1" cellspacing="0" cellpadding="2"> + <tr> + <th>File:</th> + <td> + <xsl:value-of select="@name"/> + </td> + </tr> + </table> + <table bgcolor="#DFFFFF" width="95%" border="1" cellspacing="0" cellpadding="2"> + <tr> + <th style="width: 4em; padding: 0; margin: 0;">Line</th> + <th style="width: 4em; padding: 0; margin: 0;">Column</th> + <th style="width: 7em; padding: 0; margin: 0;">Severity</th> + <th>Reason</th> + </tr> + <xsl:apply-templates select="issue"/> + </table> + <p/> + </xsl:template> + + <xsl:template match="issue"> + <tr> + <td> + <xsl:value-of select="@line"/> + </td> + <td> + <xsl:value-of select="@column"/> + </td> + <td> + <xsl:value-of select="@severity"/> + </td> + <td> + <xsl:value-of select="@reason"/> + </td> + </tr> + </xsl:template> + +</xsl:stylesheet> http://git-wip-us.apache.org/repos/asf/buildr/blob/44082045/doc/more_stuff.textile ---------------------------------------------------------------------- diff --git a/doc/more_stuff.textile b/doc/more_stuff.textile index 6f44f4b..fe26bba 100644 --- a/doc/more_stuff.textile +++ b/doc/more_stuff.textile @@ -1059,6 +1059,37 @@ The method compile_jaxb accepts either an array of files or a single file as the * <tt>:keep_content</tt>: By default the generated directory will be deleted. If <tt>true</tt> is specified for this parameter the directory will not be deleted. * <tt>:package</tt>: The package in which the source is generated. +h2(#scss_lint). ScssLint + +"ScssLint":https://github.com/causes/scss-lint is integrated into Buildr through an extension. The extension adds the "scss_lint:xml" task to generate an xml report listing scss lint violations and a "scss_lint:html" task for a html variant of the same data. A buildr project that makes uses of the extension is expected to have added 'scss_lint' gem to the projects Gemfile by adding a line such as; + +{% highlight ruby %} +gem 'scss-lint', '= 0.24.0' +{% endhighlight %} + +A typical project that uses the extension may look something like; + +{% highlight ruby %} +require 'buildr/scss_lint' + +define "foo" do + project.version = "1.0.0" + + define "bar" do ... end + + scss_lint.configuration_file = _('etc/scss_lint/checks.yml') + scss_lint.source_paths << project('web')._(:source, :main, :webapp, 'sass') + scss_lint.file_excludes = FileList["#{project('web')._(:source, :main, :webapp, 'sass')}/vendor/**/*"] +end +{% endhighlight %} + +By default scss_lint will look for all configuration files in the src/main/etc/scss_lint directory but this can be overriden by the setting the "scss_lint.config_directory" parameter. The "scss_lint:xml" task will be defined if the scss_lint rules file is found. The rules file is named "checks.yml" by default but can be overridden by setting the "scss_lint.configuration_file" parameter. + +[self.project._(:source, :main, :webapp, :sass)] +The extension will lint the sass files in the "_(:source, :main, :webapp, :sass)" directory by default. The set of source directories linted can be controlled by the "scss_lint.source_paths" parameter. + +If the xsl file named "scss_lint-report.xsl" is present in the configuration directory then that will be used in the "scss_lint:html" task otherwise a default xsl included with buildr will be used. The name of the xsl file can be overridden by the parameter "scss_lint.style_file". + h2(#anything_ruby). Anything Ruby Can Do Buildr is Ruby code. That's an implementation detail for some, but a useful features for others. You can use Ruby to keep your build scripts simple and DRY, tackle ad hoc tasks and write reusable features without the complexity of "plugins".
