Permalink
Browse files

bears/yaml: Add TravisLintBear

Closes #294
  • Loading branch information...
yash-nisar committed Jul 1, 2017
1 parent 62daca6 commit 2f004bc082178450515886c66a547e524d2c6b20
View
@@ -7,3 +7,4 @@ gem "reek"
gem "rubocop", "0.47.1"
gem "scss_lint", require: false
gem "sqlint"
gem "travis", "1.8.8"
@@ -0,0 +1,30 @@
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.GemRequirement import GemRequirement
@linter(executable='travis',
output_format='regex',
output_regex=r'\[x\]\s+(?P<message>.+)')
class TravisLintBear:
"""
A validator for your ``.travis.yml`` that attempts to reduce common build
errors such as:
- invalid YAML
- missing language key
- unsupported runtime versions of Ruby, PHP, OTP, etc.
- deprecated features or runtime aliases
"""
LANGUAGES = {'YAML'}
REQUIREMENTS = {GemRequirement('travis', '1.8.8')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting', 'Syntax'}
SEE_MORE = 'https://docs.travis-ci.com/user/travis-lint'
@staticmethod
def create_arguments(filename, file, config_file):
return 'lint', filename
@@ -0,0 +1,73 @@
import os
from queue import Queue
from coalib.results.Result import Result
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
from coalib.settings.Section import Section
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
from coalib.testing.BearTestHelper import generate_skip_decorator
from bears.yaml.TravisLintBear import TravisLintBear
def get_testfile_path(name):
return os.path.join(os.path.dirname(__file__),
'travislint_test_files',
name)
def load_testfile(name):
return open(get_testfile_path(name)).readlines()
@generate_skip_decorator(TravisLintBear)
class TravisLintBearTest(LocalBearTestHelper):
def setUp(self):
self.uut = TravisLintBear(Section('name'), Queue())
def test_good_file(self):
file_name = '.good_travis.yml'
file_contents = load_testfile(file_name)
self.check_results(
self.uut,
file_contents,
[],
filename=get_testfile_path(file_name))
def test_bad_file(self):
file_name = '.bad_travis.yml'
file_contents = load_testfile(file_name)
self.check_results(
self.uut,
file_contents,
[Result.from_values('TravisLintBear',
message='in matrix.exclude section: '
'specified ruby, but setting is '
'not relevant for python',
file=get_testfile_path(file_name),
severity=RESULT_SEVERITY.NORMAL),
Result.from_values('TravisLintBear',
message='in os section: dropping osx, does'
' not support python',
file=get_testfile_path(file_name),
severity=RESULT_SEVERITY.NORMAL),
Result.from_values('TravisLintBear',
message='specified ruby, but setting is '
'not relevant for python',
file=get_testfile_path(file_name),
severity=RESULT_SEVERITY.NORMAL)],
filename=get_testfile_path(file_name))
def test_empty_file(self):
file_name = '.empty_travis.yml'
file_contents = load_testfile(file_name)
self.check_results(
self.uut,
file_contents,
[Result.from_values('TravisLintBear',
message='missing key language, defaulting '
'to ruby',
file=get_testfile_path(file_name),
severity=RESULT_SEVERITY.NORMAL)],
filename=get_testfile_path(file_name))
@@ -0,0 +1,28 @@
language: python
sudo: false
cache: bundler
rvm:
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1.0
- 2.1.3
- jruby
os:
- linux
- osx
matrix:
exclude:
- rvm: 1.8.7
os: osx
- rvm: 1.9.2
os: osx
- rvm: 2.1.0
os: osx
- rvm: jruby
os: osx
deploy:
provider: rubygems
api_key:
secure: abcdef
gem: travis
@@ -0,0 +1,28 @@
language: ruby
sudo: false
cache: bundler
rvm:
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1.0
- 2.1.3
- jruby
os:
- linux
- osx
matrix:
exclude:
- rvm: 1.8.7
os: osx
- rvm: 1.9.2
os: osx
- rvm: 2.1.0
os: osx
- rvm: jruby
os: osx
deploy:
provider: rubygems
api_key:
secure: abcdef
gem: travis

0 comments on commit 2f004bc

Please sign in to comment.