pylint
هنتكلم اليوم عن آداة pylint
هي اداة مستخدمة للتحقق مع عدة أشياء، منها مدى موافقة الكود ل pep8 كطول السطر وأسماء المتغيرات وإستخدام الوحدات المستدعاة بجانب التحقق من الأكواد المكررة والأخطاء
هنا قائمة الرسائل التي تعطيها لك pylint
تتكامل مع بيئات تطوير ومحررات عديدة منها vim, emacs, textmate, eclipse, komodo, wing, eric, spyder
للتنصيب
pip install pylint
اسم الحزمة لفيدورا وديبيان وأوبنتو هو pylint فقم بتنصيبها عبر yum install pylint او apt-get install pylint
قمت بتشغيل pylint على كود pytorrentrename
pylint pytorrentrename.py
************* Module pytorrentrename
C: 2, 0: Trailing whitespace (trailing-whitespace)
C: 4, 0: Trailing whitespace (trailing-whitespace)
C: 9, 0: Trailing whitespace (trailing-whitespace)
C: 14, 0: Trailing whitespace (trailing-whitespace)
C: 19, 0: Trailing whitespace (trailing-whitespace)
C: 20, 0: Trailing whitespace (trailing-whitespace)
W: 29, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 31, 0: Trailing whitespace (trailing-whitespace)
W: 32, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation)
W: 33, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation)
W: 34, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation)
C: 34, 0: Exactly one space required before assignment
match = re.search(':name([\d]+):', filecontents)
^ (bad-whitespace)
C: 35, 0: Line too long (86/80) (line-too-long)
W: 35, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation)
W: 38, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 39, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 40, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 41, 0: Trailing whitespace (trailing-whitespace)
C: 42, 0: Trailing whitespace (trailing-whitespace)
W: 43, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 46, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 46, 0: Exactly one space required around assignment
torrentfilename=get_torrentfile_filename(torrentpath)
^ (bad-whitespace)
W: 47, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 48, 0: Trailing whitespace (trailing-whitespace)
W: 49, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 49, 0: Exactly one space required around assignment
torrent_name=torrentfilename+".torrent" #torrent extension
^ (bad-whitespace)
W: 50, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 51, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 51, 0: Exactly one space required around assignment
new_torrent_path=os.path.join(os.path.dirname(torrentpath), torrent_name)
^ (bad-whitespace)
W: 52, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 53, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 53, 0: Exactly one space required around assignment
new_torrent_path=new_torrent_path.replace(" ", "_")
^ (bad-whitespace)
W: 54, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 57, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 59, 0: Trailing whitespace (trailing-whitespace)
W: 61, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 61, 0: Exactly one space required around assignment
_filter_func=lambda x : "torrent" in x
^ (bad-whitespace)
C: 61, 0: No space allowed before :
_filter_func=lambda x : "torrent" in x
^ (bad-whitespace)
W: 62, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 63, 0: Trailing whitespace (trailing-whitespace)
W: 65, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 68, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 69, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 69, 0: Exactly one space required around assignment
dirlist=os.listdir(dirpath)
^ (bad-whitespace)
W: 70, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 70, 0: Exactly one space required around assignment
torrent_files=filter_torrents(dirlist)
^ (bad-whitespace)
W: 71, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 72, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 73, 0: Trailing whitespace (trailing-whitespace)
W: 75, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 75, 0: Exactly one space required around comparison
if len(sys.argv)>0:
^ (bad-whitespace)
W: 77, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 77, 0: Exactly one space required around assignment
args=[os.path.abspath(x) for x in sys.argv[1:]]
^ (bad-whitespace)
W: 78, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 79, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 80, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 81, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 82, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 83, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 84, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 85, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 86, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 87, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 88, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 89, 0: Trailing whitespace (trailing-whitespace)
W: 90, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 91, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 91, 0: Line too long (89/80) (line-too-long)
C: 92, 0: Trailing whitespace (trailing-whitespace)
C: 93, 0: Trailing whitespace (trailing-whitespace)
C: 94, 0: Exactly one space required around assignment
if __name__=="__main__":
^^ (bad-whitespace)
W: 95, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 34, 0: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
C: 1, 0: Missing module docstring (missing-docstring)
C: 39,24: Invalid variable name "f" (invalid-name)
W: 62, 8: Used builtin function 'filter' (bad-builtin)
C: 64, 0: Invalid function name "rename_directory_of_torrentfiles" (invalid-name)
C: 71, 5: Invalid variable name "f" (invalid-name)
C: 74, 0: Missing function docstring (missing-docstring)
C: 78, 6: Invalid variable name "x" (invalid-name)
W: 25, 0: Unused import argparse (unused-import)
Report
======
46 statements analysed.
Messages by category
--------------------
+-----------+-------+---------+-----------+
|type |number |previous |difference |
+===========+=======+=========+===========+
|convention |36 |36 |= |
+-----------+-------+---------+-----------+
|refactor |0 |0 |= |
+-----------+-------+---------+-----------+
|warning |45 |45 |= |
+-----------+-------+---------+-----------+
|error |0 |0 |= |
+-----------+-------+---------+-----------+
Messages
--------
+------------------------------+------------+
|message id |occurrences |
+==============================+============+
|mixed-indentation |38 |
+------------------------------+------------+
|trailing-whitespace |16 |
+------------------------------+------------+
|bad-whitespace |12 |
+------------------------------+------------+
|invalid-name |4 |
+------------------------------+------------+
|bad-indentation |4 |
+------------------------------+------------+
|missing-docstring |2 |
+------------------------------+------------+
|line-too-long |2 |
+------------------------------+------------+
|unused-import |1 |
+------------------------------+------------+
|bad-builtin |1 |
+------------------------------+------------+
|anomalous-backslash-in-string |1 |
+------------------------------+------------+
Global evaluation
-----------------
Your code has been rated at -7.61/10 (previous run: -7.61/10, +0.00)
Raw metrics
-----------
+----------+-------+------+---------+-----------+
|type |number |% |previous |difference |
+==========+=======+======+=========+===========+
|code |46 |51.11 |46 |= |
+----------+-------+------+---------+-----------+
|docstring |13 |14.44 |13 |= |
+----------+-------+------+---------+-----------+
|comment |21 |23.33 |21 |= |
+----------+-------+------+---------+-----------+
|empty |10 |11.11 |10 |= |
+----------+-------+------+---------+-----------+
Statistics by type
------------------
+---------+-------+-----------+-----------+------------+---------+
|type |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module |1 |1 |= |0.00 |0.00 |
+---------+-------+-----------+-----------+------------+---------+
|class |0 |0 |= |0 |0 |
+---------+-------+-----------+-----------+------------+---------+
|method |0 |0 |= |0 |0 |
+---------+-------+-----------+-----------+------------+---------+
|function |6 |6 |= |83.33 |16.67 |
+---------+-------+-----------+-----------+------------+---------+
Duplication
-----------
+-------------------------+------+---------+-----------+
| |now |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines |0 |0 |= |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |0.000 |= |
+-------------------------+------+---------+-----------+سنجد إستدعاء لوحدات بدون إستخدام مثل argparse والكثير من ال trailing whitespaces وخلط بين المسافات وال tabs وبعض الأسطر الطويلة أكثر من 79 حرف ومعلومات عن إفتراضية إستخدام المسافات قبل وبعد عمليات المقارنة == وأكبر من والأسماء المخالفة
الرسائل التي تظهرها pylint مقسمة على حسب نوع
التقليد Convention C وهو المخالف للطريقة القياسية للتكويد
التحذير Warning W مخالفات صغيرة غير مؤثرة
الخطأ Error E وهو خطأ برمجي لديك
الخطأ الفادح Fatal Error F وهو خطأ لايمكن الإستمرار في المعالجة بعده
Refractor R مخالفة ل good practice