Skip to main content

Static analysis tool for WeeChat scripts.

Project description

weechat-script-lint

PyPI Build Status

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

It can be used by people writing WeeChat scripts and it is automatically executed in the CI of the WeeChat official scripts repository: https://github.com/weechat/scripts/.

Installation

The script requires Python ≥ 3.7.

In a Python virtual environment:

$ pip install weechat-script-lint

Usage

See output of weechat-script-lint --help.

Checks

When a script is checked, problems are displayed on output, with one of these levels:

  • error: severe problem, the script must be fixed now (the return code of command is the number of errors)
  • warning: a deprecated feature is used (script may break in future) or there is a minor problem, the script should be fixed
  • info: information; no urgent fix needed.

Error: missing_email

Issue: the e-mail is required if the script is submitted in the official scripts repository (error can be ignored in other cases).

How to fix: add a contact e-mail in the header of the script.

Error: missing_infolist_free

Issue: when an infolist is asked to WeeChat with infolist_get, it must always be freed by a call to infolist_free, otherwise this causes a memory leak.

How to fix: call infolist_free on each pointer returned by a call to infolist_get.

Error: python2_bin (Python script only)

Issue: the info python2_bin is used to find the path to Python 2.x interpreter. Since WeeChat is compiled with Python 3 and that all scripts aim to be compatible with Python 3, this info must not be used at all any more. Note that some systems may not provide Python 2 at all any more.

How to fix: if the Python interpreter is used to run a background command, consider using function hook_process or hook_process_hashtable.

Error: mixed_tabs_spaces (Python script only)

Issue: mixed tabs and spaces are used for indentation.

How to fix: replace all tabs by spaces for indentation.

Warning: sys_exit (Python script only)

Issue: the function sys.exit() causes WeeChat to exit itself, so it must not be used in scripts.
This is a warning and not an error because if it is used when the import of weechat fails, that means the script is not executed in WeeChat and then the call to sys.exit() is harmless.

How to fix: if sys.exit() is called when the import of weechat fails, consider setting a variable instead that will prevent the call to weechat.register to be made.

Warning: deprecated_hook_completion_get_string

Issue: the function hook_completion_get_string is deprecated and should not be used any more since WeeChat 2.9.

How to fix: call the function completion_get_string.

Warning: deprecated_hook_completion_list_add

Issue: the function hook_completion_list_add is deprecated and should not be used any more since WeeChat 2.9.

How to fix: call the function completion_list_add.

Warning: deprecated_irc_nick_color

Issue: the info irc_nick_color is deprecated and should not be used any more since WeeChat 1.5.

How to fix: use the info nick_color.

Warning: deprecated_irc_nick_color_name

Issue: the info irc_nick_color_name is deprecated and should not be used any more since WeeChat 1.5.

How to fix: use the info nick_color_name.

Warning: modifier_irc_in

Issue: the modifier irc_in_xxx sends the raw IRC message to the callback which may not be UTF-8 valid. This is a problem in some languages like Python.

How to fix: use the modifier irc_in2_xxx. The modifier irc_in_xxx can be used only if the callback operates on the raw IRC message and is prepared to receive invalid UTF-8 data.

Warning: signal_irc_out

Issue: the signal irc_out_xxx sends the raw IRC message to the callback which may not be UTF-8 valid. This is a problem in some languages like Python.

How to fix: use the signal irc_out1_xxx.

Warning: signal_irc_outtags

Issue: the signal irc_outtags_xxx sends the raw IRC message to the callback which may not be UTF-8 valid. This is a problem in some languages like Python.

How to fix: use the signal irc_out1_xxx.

Info: unneeded_shebang

Issue: the shebang is not needed, except if the script can be called outside WeeChat, which is rare.

How to fix: remove the shebang, unless it is really needed.

Info: url_weechat

Issue: the WeeChat site URL is not the official one.

How to fix: replace the URL by the official one: https://weechat.org (https and no www).

Example

Default output:

$ 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
/path/to/script.py: score = 44 / 100
Not so good: 1 scripts analyzed, 1 with issues: 2 errors, 1 warnings, 1 info
Exiting with code 2

Scripts grouped by score:

$ weechat-script-lint --score --recursive /path/to/directory
2 scripts with score 100 / 100:
  /path/to/directory/test.py
  /path/to/directory/example.py
3 scripts with score 79 / 100:
  /path/to/directory/dummy.py
  /path/to/directory/fake.py
  /path/to/directory/other.py

Copyright

Copyright © 2021-2022 Sébastien Helleu

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/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weechat-script-lint-0.5.1.tar.gz (25.4 kB view details)

Uploaded Source

Built Distributions

weechat_script_lint-0.5.1-py3.10.egg (46.1 kB view details)

Uploaded Source

weechat_script_lint-0.5.1-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file weechat-script-lint-0.5.1.tar.gz.

File metadata

  • Download URL: weechat-script-lint-0.5.1.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for weechat-script-lint-0.5.1.tar.gz
Algorithm Hash digest
SHA256 728b91781efa979f56b9fc5e4b12dfe115797287355f8bec9d85e472a7a7b388
MD5 979270e21d4c61f94c6f5dcae126fc03
BLAKE2b-256 c67718a3d3f44bf3abd3ed3d944032568e29061a6d6f29784ebfa6f35974e202

See more details on using hashes here.

File details

Details for the file weechat_script_lint-0.5.1-py3.10.egg.

File metadata

File hashes

Hashes for weechat_script_lint-0.5.1-py3.10.egg
Algorithm Hash digest
SHA256 13ef3a617be8b7be98b2911a070e635fbc18e0bf891ff7debca7956f1bea6457
MD5 f28a6cda13d11c8a19d0aee853fa01b6
BLAKE2b-256 9229ecf1cce2a7a6e0b6817f4d3e2555cf584da8b678a1c7f15e7c5f4b779ae7

See more details on using hashes here.

File details

Details for the file weechat_script_lint-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for weechat_script_lint-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e4dc03488f25012b6e19ab83051ded42befb294d364094900be079a8023a298
MD5 b92a755b68938144d5d7554d3af46948
BLAKE2b-256 bf7d5a5efd93e05f0e004eee3afaa4c2068fac00fb2df06dc1928d9af25f74d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page