Skip to content

Commit

Permalink
Merge pull request #21 from shopsmart/eslint
Browse files Browse the repository at this point in the history
Eslint
  • Loading branch information
wenga86 authored Jun 24, 2019
2 parents cfda38a + 7589c6d commit a33d3c1
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 133 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## v0.5.0

Changes:

- Adds ESLint support with ES6 capabilities and AirBnB rules

Documentation:

- Updated README with `Application Setup` section for updating and installing the gem
- Updated README with `Local Developer Setup` section all developers
- Change README to reference only rake tasks

## v0.4.1
Bugfixes:

- Fix boot check

# 0.4.0
Bugfixes:

- Fix bash command

## v0.3.0

Changes:
Expand Down
104 changes: 52 additions & 52 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bd_lint (0.4.1)
bd_lint (0.5.0)
brakeman
bundler-audit
execjs
Expand All @@ -14,43 +14,43 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.1)
actionpack (= 5.2.1)
actioncable (5.2.3)
actionpack (= 5.2.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
actionmailer (5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.1)
actionview (= 5.2.1)
activesupport (= 5.2.1)
actionpack (5.2.3)
actionview (= 5.2.3)
activesupport (= 5.2.3)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.1)
activesupport (= 5.2.1)
actionview (5.2.3)
activesupport (= 5.2.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.1)
activesupport (= 5.2.1)
activejob (5.2.3)
activesupport (= 5.2.3)
globalid (>= 0.3.6)
activemodel (5.2.1)
activesupport (= 5.2.1)
activerecord (5.2.1)
activemodel (= 5.2.1)
activesupport (= 5.2.1)
activemodel (5.2.3)
activesupport (= 5.2.3)
activerecord (5.2.3)
activemodel (= 5.2.3)
activesupport (= 5.2.3)
arel (>= 9.0)
activestorage (5.2.1)
actionpack (= 5.2.1)
activerecord (= 5.2.1)
activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
marcel (~> 0.3.1)
activesupport (5.2.1)
activesupport (5.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand All @@ -63,16 +63,16 @@ GEM
bundler (~> 1.2)
thor (~> 0.18)
coderay (1.1.2)
concurrent-ruby (1.0.5)
concurrent-ruby (1.1.5)
crass (1.0.4)
diff-lcs (1.3)
docile (1.1.5)
erubi (1.7.1)
erubi (1.8.0)
execjs (2.7.0)
ffi (1.9.25)
globalid (0.4.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.1.1)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
json (2.1.0)
loofah (2.2.3)
Expand All @@ -82,14 +82,14 @@ GEM
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.0)
mimemagic (0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
mini_portile2 (2.4.0)
minitest (5.11.3)
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
parallel (1.12.0)
parser (2.4.0.2)
ast (~> 2.3)
Expand All @@ -100,36 +100,36 @@ GEM
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (2.0.6)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.1)
actioncable (= 5.2.1)
actionmailer (= 5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
activemodel (= 5.2.1)
activerecord (= 5.2.1)
activestorage (= 5.2.1)
activesupport (= 5.2.1)
rails (5.2.3)
actioncable (= 5.2.3)
actionmailer (= 5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
activemodel (= 5.2.3)
activerecord (= 5.2.3)
activestorage (= 5.2.3)
activesupport (= 5.2.3)
bundler (>= 1.3.0)
railties (= 5.2.1)
railties (= 5.2.3)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.1)
actionpack (= 5.2.1)
activesupport (= 5.2.1)
railties (5.2.3)
actionpack (= 5.2.3)
activesupport (= 5.2.3)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (2.2.2)
rake
rake (12.3.1)
rake (12.3.2)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
Expand Down Expand Up @@ -184,14 +184,14 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.0)
thor (0.20.3)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.3.0)
websocket-driver (0.7.0)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
websocket-extensions (0.1.4)

PLATFORMS
ruby
Expand All @@ -216,4 +216,4 @@ DEPENDENCIES
thor

BUNDLED WITH
1.17.1
1.17.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# BdLint
This is a developer tool designed to provide a consistant format for the Brad's Deals code base. It also adds checks for common issues like leaving debugging declarations in the code.The linter cover the following.

- Javascript ES5* (ES6 Coming Soon)
- Javascript ES5 & ES6 support
- JSON
- Ruby & Ruby on Rails
- SCSS & CSS
Expand Down
1 change: 1 addition & 0 deletions lib/bd_lint.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "bd_lint/rvm_version"
require "bd_lint/validator"
require "pre-commit"
require "plugins/pre_commit/checks/eslint"
require "plugins/pre_commit/checks/jscs"
require "bd_lint/railtie" if defined?(Rails)

Expand Down
2 changes: 1 addition & 1 deletion lib/bd_lint/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BdLint
VERSION = "0.4.1".freeze
VERSION = "0.5.0".freeze
end
3 changes: 2 additions & 1 deletion lib/generators/lint_configs/USAGE
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Description:
Adds jscs, rubocop, and scss-lint config files to your rails app
Adds eslint, jscs, rubocop, and scss-lint config files to your rails app

Example:
rails generate lint_configs

This will create:
.eslintrc.js
.jscsrc
.rubocop.yml
.scss-lint.yml
1 change: 1 addition & 0 deletions lib/generators/lint_configs/lint_configs_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class LintConfigsGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)

def copy_lint_configs
copy_file ".eslintrc.js", ".eslintrc.js"
copy_file ".jscsrc", ".jscsrc"
copy_file ".pre_commit.ignore", ".pre_commit.ignore"
copy_file ".rubocop.yml", ".rubocop.yml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def self.source_root
end

def copy_lint_configs
copy_file ".eslintrc.js", ".eslintrc.js"
copy_file ".jscsrc", ".jscsrc"
copy_file ".pre_commit.ignore", ".pre_commit.ignore"
copy_file ".rubocop.yml", ".rubocop.yml"
Expand Down
26 changes: 26 additions & 0 deletions lib/generators/lint_configs/templates/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
'env': {
'browser': true,
'es6': true,
'jasmine': true,
'jest': true
},
'extends': [
'airbnb-base',
'plugin:vue/recommended' // Add ability to parse Vue files
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module'
},
'plugins': [
'vue' // if you want to add vue support
],
'rules': {
'vue/max-attributes-per-line': 'off'
}
};
69 changes: 69 additions & 0 deletions lib/plugins/pre_commit/checks/eslint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require "pre-commit/error_list"
require "pre-commit/checks/plugin"
require "pre-commit/configuration/top_level"
require "pre-commit/checks/shell"
require "mkmf"
require "find"

module PreCommit
module Checks
class Eslint < Shell
include PreCommit::Configuration::TopLevel

def self.description
'Support for eslint linting'
end

def call(staged_files)
return 'ESLint executable could not be located' if eslint_source.nil?
# Check for .js files in the Webpack Pipeline
staged_files = staged_files.grep(/^((?!\/javascripts\/).)+\.(js|vue)$/)
return if staged_files.empty?
result = in_groups(staged_files).map do |files|
run_check(files)
end.compact

result.empty? ? nil : result.join("\n")
end

def run_check(files)
args = [eslint_source] + config_file_flag + files
execute(args)
end

def config_file_flag
config_file ? ['-c', config_file] : []
end

def alternate_config_file
'.eslintrc.js'
end

def node_modules_bin
@node_modules_bin ||= File.join(self.top_level, 'node_modules', '.bin')
end

# First look for eslint in the top_level
def app_source
@app_source ||= begin
return unless File.directory?(node_modules_bin)
Find.find(node_modules_bin) { |path| @app_source = path if path =~ /eslint$/ }
end
end

# If eslint is not in the top_level see if its defined within the system
def sys_source
@sys_source ||= MakeMakefile.find_executable('eslint')
end

def eslint_source
app_source || sys_source
end
end
end
end

# Pevents MakeMakefile from generating log file
module Logging
@logfile = File::NULL
end
16 changes: 8 additions & 8 deletions lib/plugins/pre_commit/checks/jscs.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'pre-commit/error_list'
require 'pre-commit/checks/plugin'
require 'pre-commit/configuration/top_level'
require 'pre-commit/checks/shell'
require 'mkmf'
require 'find'
require "pre-commit/error_list"
require "pre-commit/checks/plugin"
require "pre-commit/configuration/top_level"
require "pre-commit/checks/shell"
require "mkmf"
require "find"

module PreCommit
module Checks
Expand All @@ -17,8 +17,8 @@ def self.description
def call(staged_files)
return 'JSCS executable could not be located' if jscs_source.nil?

# Check for .js files
staged_files = staged_files.grep(/\.js$/)
# Check for .js files NOT in the Webpack Pipeline
staged_files = staged_files.grep(/^((?!\/packs\/).)+\.js$/)
return if staged_files.empty?
result = in_groups(staged_files).map do |files|
run_check(files)
Expand Down
Loading

0 comments on commit a33d3c1

Please sign in to comment.