337 for rulename, sequences in list(self.rules.items()):
338 logging.info("%s:", rulename)
339 for i, sequence in enumerate(sequences, 1):
340 tokens = " {}".format(i)341 for expression in sequence:
342 tokens += ' ' + self.__keyword_upper(expression)
343 logging.info("%s", tokens)
168 for rulename, sequences in list(self.rules.items()):
169 sequences_without_opts = []
170 for i, sequence in enumerate(sequences, 1):
171 sequence.append('[[{}.{}]]'.format(rulename, i)) # add original rulename.sequence172 sequences_without_opts.extend(self.__variants(sequence))
173 self.rules[rulename] = sequences_without_opts
174
352 """
353 html = '\n' + data['description']
354 html += '\n<h2>Microsoft Documentation</h2>'
355 html += '\n<p><a href="{}" target="_blank">{}</a></p>'.format(data['href'], data['key'])356 return html
357
358
320mergerules: create a merged file <clangtidy_merged.xml> from the input <clangtidy_new.xml> and <diagnostic_new.xml> files.
321
322check: for each rule in <rules.xml> generate a file "/tmp/<rule_key>.ruledump", which contains the HTML code of rules description
323 check each *.ruledump file with tidy in order to validate the HTML description""" % (script_name, script_name, script_name))324 sys.exit(1)
325
326if __name__ == "__main__":
304 merged_rules.append(rule_tag)
305 with open(output, 'w') as f:
306 write_rules_xml(merged_rules, f)
307 sys.stderr.write("[INFO] Merged rules: {}\n".format(output))308
309
310def print_usage_and_exit():
f-strings are the fastest way to format strings as compared to the following methods:
%
format()
str.join
+
operator to concatinate stringTemplate.substitute
Some less preferred ways to format strings are the following:
from string import Template
menu = ('eggs', 'spam', 42.4)
old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string]
beginner_order = menu[0] + " and " + menu[1] + ": " + str(menu[2]) + " ¤"
joined_order = " and ".join(menu[:2])
format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2])
named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2])
template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2])
Consider using f-strings as shown below:
menu = ('eggs', 'spam', 42.4)
f_string_order = f"{menu[0]} and {menu[1]}: {menu[2]:0.2f} ¤"