Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configfiles: Add NginxBear #2901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions bears/configfiles/NginxBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.DistributionRequirement \
import DistributionRequirement
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY


@linter(executable='nginx',
output_format='regex',
output_regex=r'\[(?P<severity>.+)\](?P<message>.+)'
r':(?P<line>\d+)',
severity_map={'emerg': RESULT_SEVERITY.MAJOR,
'alert': RESULT_SEVERITY.MAJOR,
'warn': RESULT_SEVERITY.NORMAL},
use_stderr=True)
class NginxBear:
"""
Checks syntax of nginx configuration files using `nginx -tc` command.
"""

LANGUAGES = {'nginx'}
REQUIREMENTS = {
DistributionRequirement(
apt_get='nginx',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. The new build system has landed, and you will need to re-run .ci/generate_bears_metadata.py, and then re-run moban , and it should update .travis.yml for you.

brew='nginx',
dnf='nginx',
portage=None,
xbps='nginx',
yum='nginx',
zypper='nginx',
),
}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Syntax'}
SEE_MORE = 'https://nginx.com'

@staticmethod
def create_arguments(filename, file, config_file):
return ('-tc', filename)
35 changes: 35 additions & 0 deletions tests/configfiles/NginxBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from bears.configfiles.NginxBear import NginxBear
from coalib.testing.LocalBearTestHelper import verify_local_bear

good_file = """
http{
server {
listen 80;

server_name example.com www.example.com;

root /usr/local/www/example.com;

access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
}
}
"""

bad_file = """
http{
server {
listen 80;

server_name example.com www.example.com;

root /usr/local/www/example.com;

access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
}
"""

NginxBearTest = verify_local_bear(NginxBear,
valid_files=(good_file, ),
invalid_files=(bad_file, ))