Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
flashcode committed Apr 19, 2021
0 parents commit a7feed8
Show file tree
Hide file tree
Showing 26 changed files with 1,695 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
- push
- pull_request

jobs:

build:

strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"

name: Python ${{ matrix.python-version }}
runs-on: ubuntu-20.04

steps:

- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pylint mypy pytest coverage pytest-cov mock
- name: Lint with flake8
run: make flake8

- name: Lint with pylint
run: make pylint

- name: Test with mypy
run: make mypy

- name: Test with pytest
run: make test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.coverage
*.pyc
*.pyo
build/
dist/
weechat_script_lint.egg-info/
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# weechat-script-lint ChangeLog

## Version 0.1.0 (2021-04-19)

- First release.
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright (C) 2021 Sébastien Helleu <[email protected]>
#
# This file is part of weechat-script-lint.
#
# Weechat-script-lint is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Weechat-script-lint is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with weechat-script-lint. If not, see <https://www.gnu.org/licenses/>.
#

all: check

check: lint test

lint: flake8 pylint mypy

flake8:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --statistics

pylint:
pylint weechat_script_lint
pylint tests/*.py

mypy:
mypy weechat_script_lint
mypy tests/*.py

test:
pytest -vv --cov-report term-missing --cov=weechat_script_lint tests
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# weechat-script-lint

[![PyPI](https://img.shields.io/pypi/v/weechat-script-lint.svg)](https://pypi.org/project/weechat-script-lint/)
[![Build Status](https://github.com/weechat/weechat-script-lint/workflows/CI/badge.svg)](https://github.com/weechat/weechat-script-lint/actions?query=workflow%3A%22CI%22)

Weechat-script-lint is a static analysis tool for WeeChat scripts.

The script just requires Python ≥ 3.7.

## Installation

```
$ pip install weechat-script-lint
```

## Example

```
$ weechat-script-lint script.py
/path/to/script.py:44: info [url_weechat]: URL http://www.weechat.org should be changed to https://weechat.org
/path/to/script.py:45: warning [sys_exit]: sys.exit() causes WeeChat to exit itself
/path/to/script.py:98: error [python2_bin]: the info python2_bin must not be used any more
/path/to/script.py:167: error [missing_infolist_free]: missing call to infolist_free
```

## Copyright

Copyright © 2021 [Sébastien Helleu](https://github.com/flashcode)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
59 changes: 59 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
#
# Copyright (C) 2021 Sébastien Helleu <[email protected]>
#
# This file is part of weechat-script-lint.
#
# Weechat-script-lint is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Weechat-script-lint is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with weechat-script-lint. If not, see <https://www.gnu.org/licenses/>.
#

from codecs import open
from setuptools import setup, find_packages
from weechat_script_lint import __version__ as wsl_version

DESCRIPTION = 'Static analysis tool for WeeChat scripts.'

with open('README.md', 'r', 'utf-8') as f:
readme = f.read()

setup(
name='weechat-script-lint',
version=wsl_version,
description=DESCRIPTION,
long_description=readme,
long_description_content_type='text/markdown',
author='Sébastien Helleu',
author_email='[email protected]',
url='https://github.com/weechat/weechat-script-lint',
license='GPL3',
keywords='static analysis weechat script lint',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 '
'or later (GPLv3+)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Software Development',
'Topic :: Utilities',
],
packages=find_packages(),
tests_require=['pytest'],
entry_points={
'console_scripts': ['weechat-script-lint=weechat_script_lint:main'],
}
)
Empty file added tests/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/scripts/not_a_script.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is not a WeeChat script.
19 changes: 19 additions & 0 deletions tests/scripts/script_all_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
#
# Author: Sébastien Helleu
#

"""A WeeChat script."""

import sys

try:
import weechat
except ImportError:
print('This script must be run under WeeChat: http://www.weechat.org')

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
python2_bin = weechat.info_get('python2_bin', '')
sys.exit(1)
Empty file added tests/scripts/script_empty.py
Empty file.
12 changes: 12 additions & 0 deletions tests/scripts/script_missing_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Author: Sébastien Helleu
#

"""A WeeChat script."""

import weechat

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
weechat.infolist_free(infolist)
11 changes: 11 additions & 0 deletions tests/scripts/script_missing_infolist_free.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Author: Sébastien Helleu <[email protected]>
#

"""A WeeChat script."""

import weechat

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
13 changes: 13 additions & 0 deletions tests/scripts/script_python2_bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Author: Sébastien Helleu <[email protected]>
#

"""A WeeChat script."""

import weechat

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
weechat.infolist_free(infolist)
python2_bin = weechat.info_get('python2_bin', '')
15 changes: 15 additions & 0 deletions tests/scripts/script_sys_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Author: Sébastien Helleu <[email protected]>
#

"""A WeeChat script."""

import sys

import weechat

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
weechat.infolist_free(infolist)
sys.exit(1)
13 changes: 13 additions & 0 deletions tests/scripts/script_unneeded_shebang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3
#
# Author: Sébastien Helleu <[email protected]>
#

"""A WeeChat script."""

import weechat

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
weechat.infolist_free(infolist)
15 changes: 15 additions & 0 deletions tests/scripts/script_url_weechat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Author: Sébastien Helleu <[email protected]>
#

"""A WeeChat script."""

try:
import weechat
except ImportError:
print('This script must be run under WeeChat: http://www.weechat.org')

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
weechat.infolist_free(infolist)
12 changes: 12 additions & 0 deletions tests/scripts/script_valid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Author: Sébastien Helleu <[email protected]>
#

"""A WeeChat script."""

import weechat

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
weechat.infolist_free(infolist)
12 changes: 12 additions & 0 deletions tests/scripts/subdir/script_valid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Author: Sébastien Helleu <[email protected]>
#

"""A valid WeeChat script."""

import weechat

if __name__ == '__main__':
if weechat.register('script', 'author', '0.1', 'GPL3', 'desc', '', ''):
infolist = weechat.infolist_get('buffer', '', '')
weechat.infolist_free(infolist)
Loading

0 comments on commit a7feed8

Please sign in to comment.