Bug 1258341 - Merge eslint-plugin-mozilla docs with the main linting docs, r?miker
This does 3 things:
1) Moves all the long descriptions for the rules into the main index.rst
document. This just makes it simpler, and there didn't seem to be much
point in having a separate document for each rule.
2) Moves index.rst to tools/lint/docs/eslint-plugin-mozilla.rst
3) Creates a new eslint.rst landing page, and includes it.
MozReview-Commit-ID: 1e3QBkMFOBe
--- a/tools/lint/docs/index.rst
+++ b/tools/lint/docs/index.rst
@@ -21,16 +21,17 @@ 2. It provides a streamlined interface f
like mach, mozreview and taskcluster.
.. toctree::
:caption: Linting User Guide
:maxdepth: 2
usage
create
+ linters/eslint
linters/flake8
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
rename from tools/lint/eslint/eslint-plugin-mozilla/docs/index.rst
rename to tools/lint/docs/linters/eslint-plugin-mozilla.rst
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/index.rst
+++ b/tools/lint/docs/linters/eslint-plugin-mozilla.rst
@@ -1,56 +1,157 @@
-.. _index:
-
=====================
Mozilla ESLint Plugin
=====================
-``balanced-listeners`` checks that every addEventListener has a
-removeEventListener (and does the same for on/off).
+
+balanced-listeners
+------------------
+
+Checks that for every occurence of 'addEventListener' or 'on' there is an
+occurence of 'removeEventListener' or 'off' with the same event name.
+
+
+components-imports
+------------------
-``components-imports`` adds the filename of imported files e.g.
-``Cu.import("some/path/Blah.jsm")`` adds Blah to the global scope.
+Checks the filename of imported files e.g. ``Cu.import("some/path/Blah.jsm")``
+adds Blah to the global scope.
+
+
+import-browserjs-globals
+------------------------
+
+When included files from the main browser UI scripts will be loaded and any
+declared globals will be defined for the current file. This is mostly useful for
+browser-chrome mochitests that call browser functions.
+
-``import-globals-from`` When the "import-globals-from <path>" comment is found
-in a file, then all globals from the file at <path> will be imported in the
-current scope.
+import-globals-from
+-------------------
+
+Parses a file for globals defined in various unique Mozilla ways.
+
+When a "import-globals-from <path>" comment is found in a file, then all globals
+from the file at <path> will be imported in the current scope. This will also
+operate recursively.
+
+This is useful for scripts that are loaded as <script> tag in a window and rely
+on each other's globals.
-``import-headjs-globals`` imports globals from head.js and from any files that
-should be imported by head.js (as far as we can correctly resolve the path).
+If <path> is a relative path, then it must be relative to the file being
+checked by the rule.
+
-``mark-test-function-used`` simply marks test (the test method) as used. This
-avoids ESLint telling us that the function is never called.
+import-headjs-globals
+---------------------
+
+Import globals from head.js and from any files that were imported by
+head.js (as far as we can correctly resolve the path).
+
+The following file import patterns are supported:
-``no-aArgs`` prevents using the hungarian notation in function arguments.
+- ``Services.scriptloader.loadSubScript(path)``
+- ``loader.loadSubScript(path)``
+- ``loadSubScript(path)``
+- ``loadHelperScript(path)``
+- ``import-globals-from path``
+
+If path does not exist because it is generated e.g.
+``testdir + "/somefile.js"`` we do our best to resolve it.
+
+The following patterns are supported:
-``no-cpows-in-tests`` checks if the file is a browser mochitest and,
-if so, checks for possible CPOW usage.
+- ``Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm");``
+- ``loader.lazyImporter(this, "name1");``
+- ``loader.lazyRequireGetter(this, "name2"``
+- ``loader.lazyServiceGetter(this, "name3"``
+- ``XPCOMUtils.defineLazyModuleGetter(this, "setNamedTimeout", ...)``
+- ``loader.lazyGetter(this, "toolboxStrings"``
+- ``XPCOMUtils.defineLazyGetter(this, "clipboardHelper"``
-``no-single-arg-cu-import`` rejects calls to "Cu.import" that do not supply a
-second argument (meaning they add the exported properties into global scope).
+
+mark-test-function-used
+-----------------------
-``reject-importGlobalProperties`` rejects calls to
-"Cu.importGlobalProperties". Use of this function is undesirable in
-some parts of the tree.
+Simply marks test (the test method) as used. This avoids ESLint telling
+us that the function is never called.
+
+
+no-aArgs
+--------
+
+Checks that function argument names don't start with lowercase 'a' followed by
+a capital letter. This is to prevent the use of Hungarian notation whereby the
+first letter is a prefix that indicates the type or intended use of a variable.
+
-``reject-some-requires`` rejects some calls to ``require``, according
-to a regexp passed in as an option.
+no-cpows-in-tests
+-----------------
+
+This rule checks if the file is a browser mochitest and, if so, checks for
+possible CPOW usage by checking for the following strings:
-``this-top-level-scope`` treats top-level assignments like
-``this.mumble = value`` as declaring a global.
+- "gBrowser.contentWindow"
+- "gBrowser.contentDocument"
+- "gBrowser.selectedBrowser.contentWindow"
+- "browser.contentDocument"
+- "window.content"
+- "content"
+- "content."
Note: These are string matches so we will miss situations where the parent
object is assigned to another variable e.g.::
var b = gBrowser;
b.content // Would not be detected as a CPOW.
-``var-only-at-top-level`` marks all var declarations that are not at the top
-level invalid.
+
+no-single-arg-cu-import
+-----------------------
+
+Rejects calls to "Cu.import" that do not supply a second argument (meaning they
+add the exported properties into global scope).
+
+
+reject-importGlobalProperties
+-----------------------------
+
+Rejects calls to ``Cu.importGlobalProperties``. Use of this function is
+undesirable in some parts of the tree.
+
+
+reject-some-requires
+--------------------
+
+This takes an option, a regular expression. Invocations of
+``require`` with a string literal argument are matched against this
+regexp; and if it matches, the ``require`` use is flagged.
+
+
+this-top-level-scope
+--------------------
+
+Treats top-level assignments like ``this.mumble = value`` as declaring a global.
+
+Note: These are string matches so we will miss situations where the parent
+object is assigned to another variable e.g.::
+
+ var b = gBrowser;
+ b.content // Would not be detected as a CPOW.
+
+
+var-only-at-top-level
+---------------------
+
+Marks all var declarations that are not at the top level invalid.
+
+
+Example
+=======
+-------+-----------------------+
| Possible values for all rules |
+-------+-----------------------+
| Value | Meaning |
+-------+-----------------------+
| 0 | Deactivated |
+-------+-----------------------+
@@ -65,23 +166,8 @@ Example configuration::
"mozilla/balanced-listeners": 2,
"mozilla/components-imports": 1,
"mozilla/import-globals-from": 1,
"mozilla/import-headjs-globals": 1,
"mozilla/mark-test-function-used": 1,
"mozilla/var-only-at-top-level": 1,
"mozilla/no-cpows-in-tests": 1,
}
-
-.. toctree::
- :maxdepth: 1
-
- balanced-listeners
- import-browserjs-globals
- import-globals
- import-headjs-globals
- mark-test-function-used
- no-aArgs
- no-cpows-in-tests
- no-single-arg-cu-import
- reject-importGlobalProperties
- reject-some-requires
- var-only-at-top-level
new file mode 100644
--- /dev/null
+++ b/tools/lint/docs/linters/eslint.rst
@@ -0,0 +1,45 @@
+ESLint
+======
+
+`ESLint`_ is a popular linter for JavaScript.
+
+Run Locally
+-----------
+
+The mozlint integration of `ESLint`_ can be run using mach:
+
+.. parsed-literal::
+
+ $ mach lint --linter eslint <file paths>
+
+Alternatively, omit the ``--linter eslint`` and run all configured linters, which will include
+ESLint.
+
+
+Configuration
+-------------
+
+The `ESLint`_ mozilla-central integration uses a blacklist to exclude certain directories from being
+linted. This lives in ``topsrcdir/.eslintignore``. If you don't wish your directory to be linted, it
+must be added here.
+
+The global configuration file lives in ``topsrcdir/.eslintrc``. This global configuration can be
+overridden by including an ``.eslintrc`` in the appropriate subdirectory. For an overview of the
+supported configuration, see `ESLint's documentation`_.
+
+
+ESLint Plugin Mozilla
+---------------------
+
+In addition to default ESLint rules, there are several Mozilla-specific rules that are defined in
+the :doc:`Mozilla ESLint Plugin <eslint-plugin-mozilla>`.
+
+
+.. _ESLint: http://eslint.org/
+.. _ESLint's documentation: http://eslint.org/docs/user-guide/configuring
+
+
+.. toctree::
+ :hidden:
+
+ eslint-plugin-mozilla
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/balanced-listeners.rst
+++ /dev/null
@@ -1,11 +0,0 @@
-.. _balanced-listeners:
-
-==================
-balanced-listeners
-==================
-
-Rule Details
-------------
-
-Checks that for every occurences of 'addEventListener' or 'on' there is an
-occurence of 'removeEventListener' or 'off' with the same event name.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/import-browserjs-globals.rst
+++ /dev/null
@@ -1,12 +0,0 @@
-.. _import-browserjs-globals:
-
-========================
-import-browserjs-globals
-========================
-
-Rule Details
-------------
-
-When included files from the main browser UI scripts will be loaded and any
-declared globals will be defined for the current file. This is mostly useful for
-browser-chrome mochitests that call browser functions.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/import-globals.rst
+++ /dev/null
@@ -1,20 +0,0 @@
-.. _import-globals:
-
-==============
-import-globals
-==============
-
-Rule Details
-------------
-
-Parses a file for globals defined in various unique Mozilla ways.
-
-When a "import-globals-from <path>" comment is found in a file, then all globals
-from the file at <path> will be imported in the current scope. This will also
-operate recursively.
-
-This is useful for scripts that are loaded as <script> tag in a window and rely
-on each other's globals.
-
-If <path> is a relative path, then it must be relative to the file being
-checked by the rule.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/import-headjs-globals.rst
+++ /dev/null
@@ -1,32 +0,0 @@
-.. _import-headjs-globals:
-
-=====================
-import-headjs-globals
-=====================
-
-Rule Details
-------------
-
-Import globals from head.js and from any files that were imported by
-head.js (as far as we can correctly resolve the path).
-
-The following file import patterns are supported:
-
-- ``Services.scriptloader.loadSubScript(path)``
-- ``loader.loadSubScript(path)``
-- ``loadSubScript(path)``
-- ``loadHelperScript(path)``
-- ``import-globals-from path``
-
-If path does not exist because it is generated e.g.
-``testdir + "/somefile.js"`` we do our best to resolve it.
-
-The following patterns are supported:
-
-- ``Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm");``
-- ``loader.lazyImporter(this, "name1");``
-- ``loader.lazyRequireGetter(this, "name2"``
-- ``loader.lazyServiceGetter(this, "name3"``
-- ``XPCOMUtils.defineLazyModuleGetter(this, "setNamedTimeout", ...)``
-- ``loader.lazyGetter(this, "toolboxStrings"``
-- ``XPCOMUtils.defineLazyGetter(this, "clipboardHelper"``
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/mark-test-function-used.rst
+++ /dev/null
@@ -1,11 +0,0 @@
-.. _mark-test-function-used:
-
-=======================
-mark-test-function-used
-=======================
-
-Rule Details
-------------
-
-Simply marks test (the test method) as used. This avoids ESLint telling
-us that the function is never called.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/no-aArgs.rst
+++ /dev/null
@@ -1,12 +0,0 @@
-.. _no-aArgs:
-
-========
-no-aArgs
-========
-
-Rule Details
-------------
-
-Checks that function argument names don't start with lowercase 'a' followed by a
-capital letter. This is to prevent the use of Hungarian notation whereby the
-first letter is a prefix that indicates the type or intended use of a variable.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/no-cpows-in-tests.rst
+++ /dev/null
@@ -1,25 +0,0 @@
-.. _no-cpows-in-tests:
-
-=================
-no-cpows-in-tests
-=================
-
-Rule Details
-------------
-
-This rule checks if the file is a browser mochitest and, if so, checks for
-possible CPOW usage by checking for the following strings:
-
-- "gBrowser.contentWindow"
-- "gBrowser.contentDocument"
-- "gBrowser.selectedBrowser.contentWindow"
-- "browser.contentDocument"
-- "window.content"
-- "content"
-- "content."
-
-Note: These are string matches so we will miss situations where the parent
-object is assigned to another variable e.g.::
-
- var b = gBrowser;
- b.content // Would not be detected as a CPOW.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/no-single-arg-cu-import.rst
+++ /dev/null
@@ -1,11 +0,0 @@
-.. _no-single-arg-cu-import:
-
-=======================
-no-single-arg-cu-import
-=======================
-
-Rule Details
-------------
-
-Rejects calls to "Cu.import" that do not supply a second argument (meaning they
-add the exported properties into global scope).
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/reject-importGlobalProperties.rst
+++ /dev/null
@@ -1,10 +0,0 @@
-.. _reject-importGlobalProperties:
-
-=============================
-reject-importGlobalProperties
-=============================
-
-Rule Details
-------------
-
-Reject calls to Cu.importGlobalProperties.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/reject-some-requires.rst
+++ /dev/null
@@ -1,12 +0,0 @@
-.. _reject-some-requires:
-
-====================
-reject-some-requires
-====================
-
-Rule Details
-------------
-
-This takes an option, a regular expression. Invocations of
-``require`` with a string literal argument are matched against this
-regexp; and if it matches, the ``require`` use is flagged.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/docs/var-only-at-top-level.rst
+++ /dev/null
@@ -1,10 +0,0 @@
-.. _var-only-at-top-level:
-
-=======================
-var-only-at-top-level
-=======================
-
-Rule Details
-------------
-
-Marks all var declarations that are not at the top level invalid.
deleted file mode 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/moz.build
+++ /dev/null
@@ -1,7 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-SPHINX_TREES['eslint-plugin-mozilla'] = 'docs'