forked from mirrors/gecko-dev
		
	 f9328d2021
			
		
	
	
		f9328d2021
		
	
	
	
	
		
			
			This for a few reasons: * The summary becomes the landing page for code quality: https://firefox-source-docs.mozilla.org/tools/static-analysis/summary.html * I don't think we need a full code quality category * Closer to the source-code-doc * All the files at the same place Differential Revision: https://phabricator.services.mozilla.com/D61767 --HG-- rename : tools/lint/docs/coding-style/coding_style_java.rst => docs/code-quality/coding-style/coding_style_java.rst rename : tools/lint/docs/coding-style/coding_style_other.rst => docs/code-quality/coding-style/coding_style_other.rst rename : tools/lint/docs/coding-style/coding_style_python.rst => docs/code-quality/coding-style/coding_style_python.rst rename : tools/lint/docs/coding-style/format_cpp_code_with_clang-format.rst => docs/code-quality/coding-style/format_cpp_code_with_clang-format.rst rename : tools/clang-tidy/docs/summary.rst => docs/code-quality/index.rst rename : tools/lint/docs/create.rst => docs/code-quality/lint/create.rst rename : tools/lint/docs/index.rst => docs/code-quality/lint/index.rst rename : tools/lint/docs/index.rst => docs/code-quality/lint/lint.rst rename : tools/lint/docs/linters/codespell.rst => docs/code-quality/lint/linters/codespell.rst rename : tools/lint/docs/linters/cpp-virtual-final.rst => docs/code-quality/lint/linters/cpp-virtual-final.rst rename : tools/lint/docs/linters/eslint-plugin-mozilla.rst => docs/code-quality/lint/linters/eslint-plugin-mozilla.rst rename : tools/lint/docs/linters/eslint-plugin-spidermonkey-js.rst => docs/code-quality/lint/linters/eslint-plugin-spidermonkey-js.rst rename : tools/lint/docs/linters/eslint.rst => docs/code-quality/lint/linters/eslint.rst rename : tools/lint/docs/linters/file-perm.rst => docs/code-quality/lint/linters/file-perm.rst rename : tools/lint/docs/linters/file-whitespace.rst => docs/code-quality/lint/linters/file-whitespace.rst rename : tools/lint/docs/linters/flake8.rst => docs/code-quality/lint/linters/flake8.rst rename : tools/lint/docs/linters/l10n.rst => docs/code-quality/lint/linters/l10n.rst rename : tools/lint/docs/linters/license.rst => docs/code-quality/lint/linters/license.rst rename : tools/lint/docs/linters/lintpref.rst => docs/code-quality/lint/linters/lintpref.rst rename : tools/lint/docs/linters/mingw-capitalization.rst => docs/code-quality/lint/linters/mingw-capitalization.rst rename : tools/lint/docs/linters/perfdocs.rst => docs/code-quality/lint/linters/perfdocs.rst rename : tools/lint/docs/linters/rstlinter.rst => docs/code-quality/lint/linters/rstlinter.rst rename : tools/lint/docs/linters/rustfmt.rst => docs/code-quality/lint/linters/rustfmt.rst rename : tools/lint/docs/usage.rst => docs/code-quality/lint/usage.rst rename : tools/clang-tidy/docs/index.rst => docs/code-quality/static-analysis.rst extra : moz-landing-system : lando
		
			
				
	
	
		
			77 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			ReStructuredText
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			ReStructuredText
		
	
	
	
	
	
| ===================
 | |
| Python Coding style
 | |
| ===================
 | |
| 
 | |
| Coding style
 | |
| ~~~~~~~~~~~~
 | |
| 
 | |
| `black <https://github.com/psf/black/>`_ is the tool used to reformat the Python code.
 | |
| 
 | |
| Linting
 | |
| ~~~~~~~
 | |
| 
 | |
| The Python linting is done by `flake8 <https://gitlab.com/pycqa/flake8>`_.
 | |
| flake8 is executed by mozlint both at review phase and in the CI.
 | |
| See the :ref:`flake8` documentation for more information.
 | |
| 
 | |
| 
 | |
| Indentation
 | |
| ~~~~~~~~~~~
 | |
| 
 | |
| Four spaces in Python code.
 | |
| 
 | |
| 
 | |
| Makefile/moz.build practices
 | |
| ----------------------------
 | |
| 
 | |
| -  Changes to makefile and moz.build variables do not require
 | |
|    build-config peer review. Any other build system changes, such as
 | |
|    adding new scripts or rules, require review from the build-config
 | |
|    team.
 | |
| -  Suffix long ``if``/``endif`` conditionals with #{ & #}, so editors
 | |
|    can display matched tokens enclosing a block of statements.
 | |
| 
 | |
|    ::
 | |
| 
 | |
|       ifdef CHECK_TYPE #{
 | |
|         ifneq ($(flavor var_type),recursive) #{
 | |
|           $(warning var should be expandable but detected var_type=$(flavor var_type))
 | |
|         endif #}
 | |
|       endif #}
 | |
| 
 | |
| -  moz.build are python and follow normal Python style.
 | |
| -  List assignments should be written with one element per line. Align
 | |
|    closing square brace with start of variable assignment. If ordering
 | |
|    is not important, variables should be in alphabetical order.
 | |
| 
 | |
|    .. code-block:: python
 | |
| 
 | |
|       var += [
 | |
|           'foo',
 | |
|           'bar'
 | |
|       ]
 | |
| 
 | |
| -  Use ``CONFIG['CPU_ARCH'] {=arm}`` to test for generic classes of
 | |
|    architecture rather than ``CONFIG['OS_TEST'] {=armv7}`` (re: bug 886689).
 | |
| 
 | |
| 
 | |
| Other advices
 | |
| ~~~~~~~~~~~~~
 | |
| 
 | |
| -  Install the
 | |
|    `mozext <https://hg.mozilla.org/hgcustom/version-control-tools/file/default/hgext/mozext>`__
 | |
|    Mercurial extension, and address every issue reported on commit,
 | |
|    qrefresh, or the output of ``hg critic``.
 | |
| -  Follow `PEP 8 <https://www.python.org/dev/peps/pep-0008/>`__.
 | |
| -  Do not place statements on the same line as ``if/elif/else``
 | |
|    conditionals to form a one-liner.
 | |
| -  Global vars, please avoid them at all cost.
 | |
| -  Exclude outer parenthesis from conditionals.Use
 | |
|    ``if x > 5:,``\ rather than ``if (x > 5):``
 | |
| -  Use string formatters, rather than var + str(val).
 | |
|    ``var = 'Type %s value is %d'% ('int', 5).``
 | |
| -  Utilize tools like
 | |
|    `pylint <https://pypi.python.org/pypi/pylint>`__ or
 | |
|    `pychecker <http://pychecker.sourceforge.net>`__ to screen
 | |
|    sources for common problems.
 | |
| -  Testing/Unit tests, please write them.
 |