Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1585 from YaleSTC/1581_install_eslint
Browse files Browse the repository at this point in the history
[1581] Remove Hound, add ESLint
  • Loading branch information
Sydney Young committed Aug 8, 2016
2 parents b89bbdd + 03cd7e7 commit e8ffd13
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends: standard
installedESLint: true
plugins:
- standard
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ diff.py
Vagrantfile
*.sublime*
coverage/
.env
.env
node_modules/*
*.swp
7 changes: 0 additions & 7 deletions .hound.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AllCops:
TargetRubyVersion: 2.3
Include:
- '**/Rakefile'
- '**/config.ru'
Expand All @@ -17,6 +18,7 @@ AllCops:
- 'lib/**/*.erb'
- 'script/**/*'
- 'vendor/**/*'
- 'node_modules/**/*'
# disable the documentation check at the start of classes / modules
Documentation:
Enabled: false
Expand Down
19 changes: 7 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ env:
secure: IHUYMK2spxorl9lUeAbAfT6btuP2qRT615bUnEuUDgYrXf9y1CdQprYWJaygou/+6aWmLL0NnxYSpOxi40bHgMKeUQnTjXVbkkqQ1Tml3cMSsjkBrx7CNUygHvDDzCQCEC6m9uZjUKMZAVzVSWlOQhSMKR7MtdsSvMCrKIgA2pM=

before_install:
- if [ $TRAVIS_PULL_REQUEST == "false" ]; then git clone https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_REPO_SLUG && cd $TRAVIS_REPO_SLUG && git checkout -qf $TRAVIS_BRANCH; fi
- if [ $TRAVIS_PULL_REQUEST == "true" ]; then git checkout -qf master && git checkout -qf $TRAVIS_COMMIT; fi
- convert -version
- gs -v
# these are all for JS linters, uncomment when they are to be used
# - npm --version
# - node --version
# - npm install -g npm
# - echo "$(npm --version) (after npm upgrade)"
# - npm install -g jshint jscs
# - npm install jshint-stylish
- npm --version
- node --version
- npm install -g npm
- npm i
- 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc'

bundler_args: --without=production staging development
Expand All @@ -31,11 +30,7 @@ before_script:
- bundle exec rake db:schema:load

script:
# JS linters, uncomment once code passes
# - jscs .
# - jshint --reporter=node_modules/jshint-stylish/stylish.js .
# rubocop Ruby / Rails linter
- bundle exec rubocop -D
- bundle exec rake check_style
- xvfb-run -a bundle exec rake

# From Travis CI Support: This will route jobs to our beta build environment,
Expand Down
69 changes: 69 additions & 0 deletions lib/tasks/style_checker.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

RUBY = /\.(rb)|(rake)$/
JS = /\.jsx?$/
RUBY_PASS = %w(true no\ offenses files\ found).freeze
JS_PASS = %w(true files\ found).freeze

EXISTING_FILES = /^[^D].*/
FILE = /^[A-Z]\t(.*)$/

desc 'Style checks files that differ from master'
task :check_style do
puts diff_output
puts "\nRunning rubocop..."
puts check_ruby
puts "\nRunning eslint..."
puts check_js
exit evaluate
end

def diff_output
"Files found in the diff:\n#{diff.join("\n")}\n"
end

def check(type:, regex:, checker:)
files = files_that_match regex
return "No #{type} files found!" if files.empty?
"#{send(checker, files)}\n#{system send(checker, files)}\n"
end

def check_ruby
@ruby_results ||= check(type: 'ruby', regex: RUBY, checker: :rubocop)
end

def check_js
@js_results ||= check(type: 'javascript', regex: JS, checker: :eslint)
end

def evaluate
return 0 if passed?
1
end

def passed?
RUBY_PASS.any? { |m| check_ruby.include? m } &&
JS_PASS.any? { |m| check_js.include? m }
end

def rubocop(files)
"rubocop -D --force-exclusion #{files}"
end

def eslint(files)
"npm run lint #{files}"
end

def diff
@diff ||= process_diff
end

def process_diff
all = `git diff master --name-status`
existing_files = all.split("\n").grep(EXISTING_FILES)
existing_files.map { |f| FILE.match(f)[1] }
end

def files_that_match(regex)
diff.grep(regex).join(' ')
end
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "reservations",
"version": "6.2.0",
"description": "[![Build Status](https://travis-ci.org/YaleSTC/reservations.svg?branch=master)](https://travis-ci.org/YaleSTC/reservations) [![Code Climate](https://codeclimate.com/github/YaleSTC/reservations/badges/gpa.svg)](https://codeclimate.com/github/YaleSTC/reservations) [![Test Coverage](https://codeclimate.com/github/YaleSTC/reservations/badges/coverage.svg)](https://codeclimate.com/github/YaleSTC/reservations) [![Dependency Status](https://gemnasium.com/YaleSTC/reservations.svg)](https://gemnasium.com/YaleSTC/reservations) [![Inline docs](http://inch-ci.org/github/yalestc/reservations.svg?branch=master&style=flat)](http://inch-ci.org/github/yalestc/reservations)",
"main": "index.js",
"directories": {
"doc": "doc",
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "node_modules/.bin/eslint"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/YaleSTC/reservations.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/YaleSTC/reservations/issues"
},
"homepage": "https://github.com/YaleSTC/reservations#readme",
"devDependencies": {
"eslint": "^2.12.0",
"eslint-config-standard": "^5.3.1",
"eslint-plugin-standard": "^1.3.2"
},
"dependencies": {
"eslint-plugin-promise": "^1.3.2"
}
}

0 comments on commit e8ffd13

Please sign in to comment.