Skip to content

Commit

Permalink
Move rule descriptions to rule class docstrings
Browse files Browse the repository at this point in the history
Taken from !243 (all credits go to user Ratfink)
Set a docstring for all rule
Remove the __init__() function for all rules
Move missing pin check from S4.1 to S4.5

Resolves KiCad#220
  • Loading branch information
cpresser committed Oct 25, 2020
1 parent 4c4a29c commit 087d59d
Show file tree
Hide file tree
Showing 41 changed files with 124 additions and 272 deletions.
4 changes: 2 additions & 2 deletions common/rulebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def name(self):
path = "".join(path.split(".")[:-1])
return path.replace('_', '.')

def __init__(self, description):
self.description = description
def __init__(self):
self.description = self.__doc__.strip().splitlines()[0].strip()
self.messageBuffer=[]
self.resetErrorCount()
self.resetWarningCount()
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F5_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import cmath

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, "Silkscreen layer requirements")
"""Silkscreen layer requirements"""

def checkReference(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F5_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, "Fabrication layer requirements")
"""Fabrication layer requirements"""

# Check for presence of component value
def checkMissingValue(self):
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F5_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
from boundingbox import BoundingBox

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, "Courtyard layer requirements")
"""Courtyard layer requirements"""

# Get the superposed boundary of pads and fab layer
def getFootprintBounds(self):
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F5_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, "Elements on the graphic layer should not overlap")
"""Elements on the graphic layer should not overlap"""

def getCirclesOverlap(self,circles):
def is_same(c1, c2):
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F6_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'For surface-mount devices, placement type must be set to "Surface Mount"')
"""For surface-mount devices, placement type must be set to "Surface Mount" """

def check(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F6_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from math import sqrt

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args,'For surface-mount devices, footprint anchor is placed in the middle of the footprint (IPC-7351).')
"""For surface-mount devices, footprint anchor is placed in the middle of the footprint (IPC-7351)."""

def check(self):
"""
Expand Down
12 changes: 4 additions & 8 deletions pcb/rules/F6_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Pad requirements for SMD footprints')

self.required_layers = ["Cu", "Paste", "Mask"]
self.sides = ["F.", "B."]
"""Pad requirements for SMD footprints"""

required_layers = ["Cu", "Paste", "Mask"]
sides = ["F.", "B."]

def checkPads(self, pads):

Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F7_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'For through-hole devices, placement type must be set to "Through Hole"')
"""For through-hole devices, placement type must be set to "Through Hole" """

def check(self):
"""
Expand Down
12 changes: 4 additions & 8 deletions pcb/rules/F7_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'For through-hole components, footprint anchor is set on pad 1')

self.pin1_position = []
self.pin1_count = 0
"""For through-hole components, footprint anchor is set on pad 1"""

pin1_position = []
pin1_count = 0

def check(self):
"""
Expand Down
12 changes: 4 additions & 8 deletions pcb/rules/F7_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Pad 1 should be denoted by rectangular pad')

self.names = ['1', 'A', 'A1', 'P1', 'PAD1']
self.pad_1_shapes = ['rect', 'roundrect']
"""Pad 1 should be denoted by rectangular pad"""

names = ['1', 'A', 'A1', 'P1', 'PAD1']
pad_1_shapes = ['rect', 'roundrect']

def check(self):

Expand Down
10 changes: 2 additions & 8 deletions pcb/rules/F7_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Pad requirements for THT footprints')

self.required_layers = ["*.Cu","*.Mask"]

"""Pad requirements for THT footprints"""

required_layers = ["*.Cu","*.Mask"]

def checkPads(self, pads):

Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F7_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Annular ring must be at least 0.15mm')
"""Minimum annular ring width"""

def checkPad(self, pad):
if not 'size' in pad['drill']:
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F7_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Minimum hole drill size')
"""Minimum hole drill size"""

def checkPad(self, pad):

Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F9_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import os

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Footprint metadata must be filled as appropriate')
"""Footprint meta-data is filled in as appropriate"""

def checkDocs(self):
mod = self.module
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/F9_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from rules.rule import *

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Footprint properties should be left to default values.')
"""Footprint properties should be left to default values"""

def check(self):
"""
Expand Down
7 changes: 1 addition & 6 deletions pcb/rules/F9_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
SYSMOD_PREFIX = "${KISYS3DMOD}/"

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad_mod files.
"""
"""Footprint 3D model requirements"""

# Regular expression for suffixes that shouldn't be in the model file
suffix_re = (
Expand All @@ -21,9 +19,6 @@ class Rule(KLCRule):
')'
)

def __init__(self, module, args):
super(Rule, self).__init__(module, args, '3D model settings')

def checkModel(self, model):

error = False
Expand Down
15 changes: 6 additions & 9 deletions pcb/rules/G1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import re

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Illegal characters in footprint name')
# Set of allowed chars. Some characters need to be escaped.
allowed_chars = "a-zA-Z0-9_\-\.,\+"
self.pattern = re.compile('^['+allowed_chars+']+$')
self.forbidden = re.compile('([^'+allowed_chars+'])+')
"""Only standard characters are used for naming libraries and components"""

# Set of allowed chars. Some characters need to be escaped.
allowed_chars = "a-zA-Z0-9_\-\.,\+"
pattern = re.compile('^['+allowed_chars+']+$')
forbidden = re.compile('([^'+allowed_chars+'])+')

def check(self):
name = str(self.module.name).lower()
Expand Down
6 changes: 1 addition & 5 deletions pcb/rules/G1_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import platform

class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, module, args):
super(Rule, self).__init__(module, args, 'Library files must use Unix-style line endings (LF)')
"""Library files must use Unix-style line endings (LF)"""

def check(self):

Expand Down
4 changes: 2 additions & 2 deletions pcb/rules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class KLCRule(KLCRuleBase):
"""
A base class to represent a KLC rule
"""
def __init__(self, module, args, description):
def __init__(self, module, args):

KLCRuleBase.__init__(self, description)
KLCRuleBase.__init__(self)

self.module = module
self.args = args
Expand Down
13 changes: 4 additions & 9 deletions schlib/check_kicad_sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def do_unittest(symbol, rules, metrics):
for rule in rules:
rule.footprints_dir = args.footprints if args.footprints else None
rule = rule(symbol)
if unittest_rule == rule.name and rule.v6 == True:
if unittest_rule == rule.name:
rule.check()
if unittest_result == 'Fail' and rule.errorCount == 0:
printer.red("Test '{sym}' failed".format(sym=symbol.name))
Expand Down Expand Up @@ -56,14 +56,9 @@ def do_rulecheck(symbol, rules, metrics):
rule.footprints_dir = args.footprints if args.footprints else None
rule = rule(symbol)

# check if this rule already is v6 compatible
if rule.v6 == True:
if verbosity > 2:
printer.white("Checking rule " + rule.name)
rule.check()
else:
continue

if verbosity > 2:
printer.white("Checking rule " + rule.name)
rule.check()

if args.nowarnings and not rule.hasErrors():
continue
Expand Down
7 changes: 1 addition & 6 deletions schlib/rules/EC02.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@


class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
v6 = True
def __init__(self, component):
super(Rule, self).__init__(component, 'Check part reference, name and footprint position and alignment')
"""Check part reference, name and footprint position and alignment"""

def check(self):
"""
Expand Down
7 changes: 1 addition & 6 deletions schlib/rules/G1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@


class Rule(KLCRule):
v6 = True
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Illegal characters in symbol name')
"""Only standard characters are used for naming libraries and components"""

def check(self):

Expand Down
9 changes: 2 additions & 7 deletions schlib/rules/G1_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
import platform

class Rule(KLCRule):
v6 = True
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Library files must use Unix-style line endings (LF)')
self.lib_error = False
"""Library files must use Unix-style line endings (LF)"""
lib_error = False

def check(self):
# Only perform this check on linux systems (i.e. Travis)
Expand Down
7 changes: 1 addition & 6 deletions schlib/rules/S3_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@


class Rule(KLCRule):
v6 = True
"""
Create the methods check and fix to use with the kicad lib files.
"""
def __init__(self, component):
super(Rule, self).__init__(component, 'Origin is centered on the middle of the symbol')
"""Origin is centered on the middle of the symbol"""

def check(self):
"""
Expand Down
7 changes: 1 addition & 6 deletions schlib/rules/S3_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@


class Rule(KLCRule):
"""
Create the methods check and fix to use with the kicad lib files.
"""
v6 = True
def __init__(self, component):
super(Rule, self).__init__(component, 'Text properties should use common size of 50mils, but labels and numbers may use text size as low as 20mil if required')
"""Text fields should use a common text size of 50mils"""

def check(self):
"""
Expand Down
Loading

0 comments on commit 087d59d

Please sign in to comment.