diff options
Diffstat (limited to 'comm/tools/lint')
23 files changed, 694 insertions, 0 deletions
diff --git a/comm/tools/lint/Generated.txt b/comm/tools/lint/Generated.txt new file mode 100644 index 0000000000..c3d6090373 --- /dev/null +++ b/comm/tools/lint/Generated.txt @@ -0,0 +1,3 @@ +comm/mailnews/extensions/newsblog/test/unit/resources/feeds-missing-timestamp/feeds.json +comm/mailnews/extensions/newsblog/test/unit/resources/feeds-simple/feeditems.json +comm/mailnews/extensions/newsblog/test/unit/resources/feeds-simple/feeds.json diff --git a/comm/tools/lint/ThirdPartyPaths.txt b/comm/tools/lint/ThirdPartyPaths.txt new file mode 100644 index 0000000000..4b2922e585 --- /dev/null +++ b/comm/tools/lint/ThirdPartyPaths.txt @@ -0,0 +1,18 @@ +comm/calendar/base/modules/Ical.jsm +comm/chat/protocols/matrix/lib +comm/chat/protocols/xmpp/lib +comm/mail/base/content/protovis-r2.6-modded.js +comm/mail/components/compose/texzilla/TeXZilla.js +comm/mail/components/storybook/storybook-static +comm/mailnews/mapi/include +comm/third_party/asn1js +comm/third_party/botan +comm/third_party/bzip2 +comm/third_party/json-c +comm/third_party/libgcrypt +comm/third_party/libgpg-error +comm/third_party/libotr +comm/third_party/niwcompat +comm/third_party/python +comm/third_party/rnp +comm/third_party/zlib diff --git a/comm/tools/lint/black.yml b/comm/tools/lint/black.yml new file mode 100644 index 0000000000..a3850bc7be --- /dev/null +++ b/comm/tools/lint/black.yml @@ -0,0 +1,16 @@ +--- +black: + description: Reformat python + include: + - comm/ + extensions: + - build + - configure + - mozbuild + - py + support-files: + - 'tools/lint/python/**' + type: external + payload: commlint:lint_wrapper + wraps: commlint:black_lint + setup: python.black:setup diff --git a/comm/tools/lint/codespell.yml b/comm/tools/lint/codespell.yml new file mode 100644 index 0000000000..08b68aac81 --- /dev/null +++ b/comm/tools/lint/codespell.yml @@ -0,0 +1,47 @@ +--- +codespell: + description: Check code for common misspellings + include: + - comm/calendar/locales/en-US/ + - comm/chat/locales/en-US/ + - comm/mail/branding/ + - comm/mail/components/telemetry/ + - comm/mail/locales/en-US/ + - comm/mailnews/extensions/fts3/ + - comm/python/ + - comm/taskcluster/docs/ + - comm/third_party/ + - comm/README.md + exclude: + # Timezones have oddly spelled words that tend to confuse codespell + - comm/calendar/locales/en-US/chrome/calendar/timezones.properties + - comm/mailnews/extensions/fts3/fts3_porter.c + # List of extensions coming from: + # tools/lint/{flake8,eslint}.yml + # tools/mach_commands.py (clang-format) + # + documentation + # + localization files + extensions: + - js + - jsm + - jxs + - mjs + - xml + - html + - xhtml + - cpp + - c + - h + - configure + - py + - properties + - rst + - md + - ftl + support-files: + - 'tools/lint/spell/**' + - 'comm/tools/lint/spell/**' + type: external + setup: spell:setup + payload: commlint:lint_wrapper + wraps: spell:lint diff --git a/comm/tools/lint/commlint/__init__.py b/comm/tools/lint/commlint/__init__.py new file mode 100644 index 0000000000..19d887e109 --- /dev/null +++ b/comm/tools/lint/commlint/__init__.py @@ -0,0 +1,111 @@ +# 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/. + +import os +from contextlib import contextmanager +from pathlib import Path + +from mozlint.pathutils import expand_exclusions +from mozlint.types import supported_types +from mozpack import path as mozpath + +COMM_EXCLUSION_FILES = [ + os.path.join("comm", "tools", "lint", "ThirdPartyPaths.txt"), + os.path.join("comm", "tools", "lint", "Generated.txt"), +] + +TASKCLUSTER_EXCLUDE_PATHS = (os.path.join("comm", "suite"),) + + +@contextmanager +def pushd(dest_path: Path): + """ + Sets the cwd within the context + :param Path dest_path: The path to the cwd + """ + origin = Path().absolute() + try: + os.chdir(dest_path) + yield + finally: + os.chdir(origin) + + +def _apply_global_excludes(root, config): + exclude = config.get("exclude", []) + + for path in COMM_EXCLUSION_FILES: + with open(os.path.join(root, path), "r") as fh: + exclude.extend([mozpath.join(root, f.strip()) for f in fh.readlines()]) + + if os.environ.get("MOZLINT_NO_SUITE", None): + # Ignore Seamonkey-only paths when run from Taskcluster + suite_excludes = [mozpath.join(root, path) for path in TASKCLUSTER_EXCLUDE_PATHS] + exclude.extend(suite_excludes) + + config["exclude"] = exclude + + +# This makes support file paths absolute, allowing lintpref to find StaticPrefList.yaml +def _expand_support_files(root, config): + support_files = config.get("support-files", []) + absolute_support_files = [mozpath.join(root, f) for f in support_files] + config["support-files"] = absolute_support_files + + +def eslint_wrapper(paths, config, **lintargs): + comm_root = Path(lintargs["root"]) / "comm" + with pushd(comm_root): + rv = lint_wrapper(paths, config, **lintargs) + + return rv + + +def stylelint_wrapper(paths, config, **lintargs): + comm_root = Path(lintargs["root"]) / "comm" + + ignore_file = str(comm_root / ".stylelintignore") + lintargs.setdefault("extra_args", []) + lintargs["extra_args"].extend(["--ignore-path", ignore_file]) + + with pushd(comm_root): + rv = lint_wrapper(paths, config, **lintargs) + + return rv + + +def black_lint(paths, config, fix=None, **lintargs): + from python.black import run_black + + files = list(expand_exclusions(paths, config, lintargs["root"])) + + # prepend "--line-length 99" to files, it will be processed as an argument + black_args = ["-l", "99"] + files + + return run_black( + config, + black_args, + fix=fix, + log=lintargs["log"], + virtualenv_bin_path=lintargs.get("virtualenv_bin_path"), + ) + + +def lint_wrapper(paths, config, **lintargs): + _apply_global_excludes(lintargs["root"], config) + _expand_support_files(lintargs["root"], config) + + payload = supported_types[config.get("wrappedType", config["type"])] + config["payload"] = config["wraps"] + del config["wraps"] + + if config.get("wrappedType", ""): + config["type"] = config["wrappedType"] + del config["wrappedType"] + + if config.get("commroot", False): + lintargs["root"] = os.path.join(lintargs["root"], "comm") + del config["commroot"] + + return payload(paths, config, **lintargs) diff --git a/comm/tools/lint/commlint/l10n_lint.py b/comm/tools/lint/commlint/l10n_lint.py new file mode 100644 index 0000000000..ad880d5cde --- /dev/null +++ b/comm/tools/lint/commlint/l10n_lint.py @@ -0,0 +1,16 @@ +# 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/. + +from python.l10n_lint import lint_strings, strings_repo_setup + +LOCALE = "comm-strings-quarantine" +STRINGS_REPO = "https://hg.mozilla.org/projects/comm-strings-quarantine" + + +def comm_strings_setup(**lint_args): + return strings_repo_setup(STRINGS_REPO, LOCALE) + + +def lint(paths, lintconfig, **lintargs): + return lint_strings(LOCALE, paths, lintconfig, **lintargs) diff --git a/comm/tools/lint/eslint.yml b/comm/tools/lint/eslint.yml new file mode 100644 index 0000000000..f7ab22e0e8 --- /dev/null +++ b/comm/tools/lint/eslint.yml @@ -0,0 +1,18 @@ +--- +eslint: + description: JavaScript linter + # ESLint infra handles its own path filtering, so just include cwd + include: ['.'] + exclude: [] + extensions: ['mjs', 'js', 'jsm', 'json', 'jsx', 'html', 'sjs', 'xhtml'] + support-files: + - 'comm/**/.eslintrc.js' + - 'comm/.eslintignore' + - 'comm/.prettierignore' + - 'tools/lint/eslint/**' + # Files that can influence global variables + - 'toolkit/modules/Services.jsm' + type: external + payload: commlint:eslint_wrapper + wraps: eslint:lint + setup: eslint:setup diff --git a/comm/tools/lint/file-perm.yml b/comm/tools/lint/file-perm.yml new file mode 100644 index 0000000000..aa20787d14 --- /dev/null +++ b/comm/tools/lint/file-perm.yml @@ -0,0 +1,55 @@ +--- +file-perm: + description: File permission check + include: + - comm/ + extensions: + - .build + - .c + - .cc + - .cpp + - .flac + - .h + - .html + - .idl + - .js + - .jsm + - .jsx + - .m + - .md + - .m4s + - .mjs + - .mm + - .mozbuild + - .mp4 + - .png + - .rs + - .rst + - .svg + - .ttf + - .wasm + - .webidl + - .xhtml + - .xml + - .xul + - .yml + support-files: + - 'tools/lint/file-perm/**' + type: external + payload: commlint:lint_wrapper + wraps: file-perm:lint + +maybe-shebang-file-perm: + description: "File permission check for files that might have `#!` header." + include: + - . + allow-shebang: true + extensions: + - .js + - .py + - .sh + support-files: + - 'tools/lint/file-perm/**' + type: external + payload: commlint:lint_wrapper + wraps: file-perm:lint diff --git a/comm/tools/lint/file-whitespace.yml b/comm/tools/lint/file-whitespace.yml new file mode 100644 index 0000000000..cd09b9c736 --- /dev/null +++ b/comm/tools/lint/file-whitespace.yml @@ -0,0 +1,27 @@ +--- +file-whitespace: + description: File content sanity check + include: + - comm/. + extensions: + - .c + - .cc + - .cpp + - .css + - .dtd + - .idl + - .ftl + - .h + - .html + - .md + - .properties + - .py + - .rs + - .rst + - .webidl + - .xhtml + support-files: + - 'tools/lint/file-whitespace/**' + type: external + payload: commlint:lint_wrapper + wraps: file-whitespace:lint diff --git a/comm/tools/lint/fluent-lint.yml b/comm/tools/lint/fluent-lint.yml new file mode 100644 index 0000000000..bb8ec8443a --- /dev/null +++ b/comm/tools/lint/fluent-lint.yml @@ -0,0 +1,18 @@ +--- +fluent-lint: + description: Linter for Fluent files + include: + - . + exclude: + - dom/l10n/tests/mochitest/document_l10n/non-system-principal/localization/test.ftl + extensions: ['ftl'] + support-files: + - 'tools/lint/fluent-lint/*.py' + - 'comm/tools/lint/fluent-lint/**' + brand-files: + - 'comm/mail/branding/thunderbird/locales/en-US/brand.ftl' + - 'toolkit/locales/en-US/toolkit/branding/brandings.ftl' + type: external + payload: commlint:lint_wrapper + wraps: fluent-lint:lint + commroot: true diff --git a/comm/tools/lint/fluent-lint/exclusions.yml b/comm/tools/lint/fluent-lint/exclusions.yml new file mode 100644 index 0000000000..9701e39086 --- /dev/null +++ b/comm/tools/lint/fluent-lint/exclusions.yml @@ -0,0 +1,82 @@ +# 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/. + +# Warning: Only exclusions for identifiers (ID01) are currently allowed. +--- +# Only add exceptions to this file if the ID is generated programmatically and +# can't easily be changed to follow the naming convention. +# Only lowercase letters and hyphens should be used in Fluent IDs. +ID01: + messages: + - accounts-ID + - msg-compose-partially-encrypted-inlinePGP + - trademarkInfo + # aboutDialog.ftl - exclusions same as Firefox + - aboutDialog-title + - aboutDialog-version + - aboutDialog-version-nightly + files: + # Files listed here must not have a comm/ prefix + # policies-descriptions.ftl: These IDs are generated programmatically + # from policy names. + - mail/locales/en-US/messenger/policies/policies-descriptions.ftl + # The webext-perms-description-* IDs are generated programmatically + - mail/locales/en-US/messenger/extensionPermissions.ftl +ID02: + messages: + # comm/mail/locales/en-US/messenger/accountCentral.ftl + - read + - compose + - search + - filter + - e2e + # comm/mail/locales/en-US/messenger/otr/am-im-otr.ftl + - otr-log + # comm/mail/locales/en-US/messenger/otr/auth.ftl + - otr-auth + - auth-yes + - auth-no + - auth-how + # comm/mail/locales/en-US/messenger/otr/otr.ftl + - resent + # comm/mail/locales/en-US/messenger/preferences/passwordManager.ftl + - remove + - import + # comm/mail/locales/en-US/messenger/preferences/preferences.ftl + - ab-label + - keep-ask + files: [] +# Hard-coded brand names like Firefox or Mozilla should be used only in +# specific cases, in all other cases the corresponding terms should be used. +# Check with the localization team for advice. +CO01: + messages: + # comm/mail/branding/thunderbird/locales/en-US/brand.ftl + - trademarkInfo + # comm/mail/locales/en-US/messenger/aboutRights.ftl + - rights-intro-point-1 + - rights-intro-point-2 + # comm/mail/locales/en-US/messenger/accountcreation/accountSetup.ftl + - account-setup-looking-up-db + - account-setup-success-settings-db + - account-setup-insecure-description + # Importers keep "Thunderbird" since that refers to a profile import + # of an installed Thunderbird application on the user's machine + # aboutImport.ftl + - app-name-thunderbird + - file-profile-description + # importDialog.ftl + - thunderbird-import-name + - thunderbird-import-description + - import-from-thunderbird-zip + - import-from-thunderbird-dir + # accountCentral.ftl - Donation appeals and descriptions about the Org + # rather than the product + - about-paragraph + - about-paragraph-consider-donation + # accountProvisioner.ftl - Refers to agreements made between the Org and + # third parties + - account-provisioner-mail-account-description + - account-provisioner-domain-description + files: [] diff --git a/comm/tools/lint/l10n.yml b/comm/tools/lint/l10n.yml new file mode 100644 index 0000000000..4a01e2b127 --- /dev/null +++ b/comm/tools/lint/l10n.yml @@ -0,0 +1,41 @@ +--- +l10n: + description: Localization linter + # list of include directories of both + # comm/mail and comm/calendar l10n.tomls + # Paths that are not part of Thunderbird (editor/browser/devtools/etc) + # are included to + include: + - browser/locales/en-US/pdfviewer + - comm/calendar/locales/en-US + - comm/chat/locales/en-US + - comm/mail/branding/thunderbird/locales/en-US + - comm/mail/locales/en-US + - comm/tools/lint/l10n.yml + - devtools/client/locales/en-US + - devtools/shared/locales/en-US + - devtools/startup/locales/en-US + - dom/locales/en-US + - netwerk/locales/en-US + - security/manager/locales/en-US + - toolkit/locales/en-US + # files not supported by compare-locales, + # and also not relevant to this linter + exclude: + - comm/mail/locales/en-US/all-l10n.js + - comm/mail/extensions/openpgp/test + - comm/calendar/locales/en-US/README.txt + l10n_configs: + - comm/mail/locales/l10n.toml + - comm/calendar/locales/l10n.toml + type: external + payload: commlint:lint_wrapper + wraps: commlint.l10n_lint:lint + setup: commlint.l10n_lint:comm_strings_setup + support-files: + - 'comm/calendar/locales/l10n.toml' + - 'comm/mail/locales/l10n.toml' + - 'comm/tools/lint/l10n.yml' + - 'third_party/python/compare-locales/**' + - 'third_party/python/fluent/**' + - 'tools/lint/python/l10n_lint.py' diff --git a/comm/tools/lint/license.yml b/comm/tools/lint/license.yml new file mode 100644 index 0000000000..255d06595a --- /dev/null +++ b/comm/tools/lint/license.yml @@ -0,0 +1,51 @@ +--- +license: + description: License Check + include: + - comm/ + exclude: + # By design + - comm/build/macosx/hardenedruntime/developer.entitlements.xml + - comm/build/macosx/hardenedruntime/production.entitlements.xml + # License not super clear, Firefox excludes its branding + - comm/mail/branding/ + # Mostly empty file + - comm/mail/base/content/overrides/app-license-name.html + # Need to verify + - comm/mail/components/im/messages + # Public Domain, but do not match pre-approved strings from Mozilla + - comm/mailnews/db/mork/morkDeque.cpp + - comm/mailnews/db/mork/morkDeque.h + # No license for README files + - comm/mailnews/jsaccount/readme.html + # License file in directory + - comm/mailnews/mime/jsmime + extensions: + - .c + - .cc + - .cpp + - .css + - .dtd + - .ftl + - .h + - .html + - .idl + - .java + - .js + - .jsm + - .jsx + - .m + - .mjs + - .mm + - .properties + - .py + - .rs + - .svg + - .xhtml + - .xml + - .xul + support-files: + - 'tools/lint/license/**' + type: external + payload: commlint:lint_wrapper + wraps: license:lint diff --git a/comm/tools/lint/lintpref.yml b/comm/tools/lint/lintpref.yml new file mode 100644 index 0000000000..2e45627925 --- /dev/null +++ b/comm/tools/lint/lintpref.yml @@ -0,0 +1,20 @@ +--- +lintpref: + description: Linter for static prefs. + include: + - 'comm/calendar/base/calendar.js' + - 'comm/chat/chat-prefs.js' + - 'comm/mail/app/profile/' + - 'comm/mail/branding/' + - 'comm/mail/components/compose/composer.js' + - 'comm/mail/components/im/all-im.js' + - 'comm/mail/locales/en-US/all-l10n.js' + - 'comm/mailnews/extensions/mdn/mdn.js' + - 'comm/mailnews/mailnews.js' + exclude: [] + extensions: ['js'] + type: external + payload: commlint:lint_wrapper + wraps: libpref:checkdupes + support-files: + - 'modules/libpref/init/StaticPrefList.yaml' diff --git a/comm/tools/lint/mach_commands.py b/comm/tools/lint/mach_commands.py new file mode 100644 index 0000000000..da503b2016 --- /dev/null +++ b/comm/tools/lint/mach_commands.py @@ -0,0 +1,24 @@ +# 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/. + +from mach.decorators import Command + + +def setup_argument_parser(): + from mozlint import cli + + return cli.MozlintParser() + + +@Command( + "commlint", + category="thunderbird", + description="Run linters with Thunderbird configurations.", + parser=setup_argument_parser, +) +def commlint(command_context, paths, extra_args=[], **kwargs): + kwargs["config_paths"].insert(0, "comm/tools/lint") + return command_context._mach_context.commands.dispatch( + "lint", command_context._mach_context, paths=paths, argv=extra_args, **kwargs + ) diff --git a/comm/tools/lint/mingw-capitalization.yml b/comm/tools/lint/mingw-capitalization.yml new file mode 100644 index 0000000000..e6679988ab --- /dev/null +++ b/comm/tools/lint/mingw-capitalization.yml @@ -0,0 +1,10 @@ +--- +mingw-capitalization: + description: > + "A Windows include file is not lowercase, and may break the MinGW build" + extensions: ['h', 'cpp', 'cc', 'c'] + include: ['comm/'] + type: external + level: error + payload: commlint:lint_wrapper + wraps: cpp.mingw-capitalization:lint diff --git a/comm/tools/lint/rejected-words.yml b/comm/tools/lint/rejected-words.yml new file mode 100644 index 0000000000..28d958568f --- /dev/null +++ b/comm/tools/lint/rejected-words.yml @@ -0,0 +1,32 @@ +--- +avoid-blacklist-and-whitelist: + description: "Use words like 'skip', 'select', 'allow' or 'deny' instead" + level: error + include: ['comm/'] + exclude: + - comm/tools/lint/rejected-words.yml + type: external + wrappedType: regex + payload: commlint:lint_wrapper + wraps: (black|white)[-_]?list + ignore-case: true + # same as codespell + extensions: + - c + - configure + - cpp + - ftl + - h + - html + - idl + - js + - jsm + - jxs + - md + - mjs + - properties + - py + - rst + - xhtml + - xml + - yml diff --git a/comm/tools/lint/ruff.yml b/comm/tools/lint/ruff.yml new file mode 100644 index 0000000000..1b7eb8a56b --- /dev/null +++ b/comm/tools/lint/ruff.yml @@ -0,0 +1,17 @@ +--- +ruff: + description: An extremely fast Python linter, written in Rust + include: ["."] + extensions: ["py"] + support-files: + - "comm/**/.ruff.toml" + - "comm/**/ruff.toml" + - "comm/**/pyproject.toml" + - "tools/lint/python/ruff.py" + # Rules that should result in warnings rather than errors. + warning-rules: [PLR, PLW] + commroot: true + type: external + payload: commlint:lint_wrapper + wraps: python.ruff:lint + setup: python.ruff:setup diff --git a/comm/tools/lint/shellcheck.yml b/comm/tools/lint/shellcheck.yml new file mode 100644 index 0000000000..a51796c14e --- /dev/null +++ b/comm/tools/lint/shellcheck.yml @@ -0,0 +1,14 @@ +--- +shellcheck: + description: Shell script linter + include: + - comm/ + # 1090: https://github.com/koalaman/shellcheck/wiki/SC1090 + # 'Can't follow a non-constant source' + extensions: ['sh'] + support-files: + - 'tools/lint/shell/**' + excludecodes: ['1090', '1091'] + type: external + payload: commlint:lint_wrapper + wraps: shell:lint diff --git a/comm/tools/lint/spell/exclude-list.txt b/comm/tools/lint/spell/exclude-list.txt new file mode 100644 index 0000000000..c9c6691027 --- /dev/null +++ b/comm/tools/lint/spell/exclude-list.txt @@ -0,0 +1,28 @@ +1nd +aare +acount +aNumber +aparent +cas +complies +crate +delink +dur +falsy +files' +fpr +incrementall +keyserver +keyservers +msdos +nd +Nd +optin +referer +te +thru +tring +ue +warmup +wasn +whats diff --git a/comm/tools/lint/stylelint.yml b/comm/tools/lint/stylelint.yml new file mode 100644 index 0000000000..f23297cd26 --- /dev/null +++ b/comm/tools/lint/stylelint.yml @@ -0,0 +1,17 @@ +--- +stylelint: + description: CSS linter + # Stylelint infra handles its own path filtering, so just include cwd + include: ['.'] + exclude: [] + extensions: ['css'] + support-files: + - 'package.json' + - 'comm/**/.stylelintrc.js' + - 'comm/.stylelintignore' + - 'tools/lint/stylelint/**' + type: external + stylelint-rc: comm/.stylelintrc.js + payload: commlint:stylelint_wrapper + wraps: stylelint:lint + setup: stylelint:setup diff --git a/comm/tools/lint/trojan-source.yml b/comm/tools/lint/trojan-source.yml new file mode 100644 index 0000000000..ba030bff28 --- /dev/null +++ b/comm/tools/lint/trojan-source.yml @@ -0,0 +1,17 @@ +--- +trojan-source: + description: Trojan Source attack - CVE-2021-42572 + include: + - comm/ + extensions: + - .c + - .cc + - .cpp + - .h + - .py + - .rs + support-files: + - 'tools/lint/trojan-source/**' + type: external + payload: commlint:lint_wrapper + wraps: trojan-source:lint diff --git a/comm/tools/lint/yaml.yml b/comm/tools/lint/yaml.yml new file mode 100644 index 0000000000..9451d52d3c --- /dev/null +++ b/comm/tools/lint/yaml.yml @@ -0,0 +1,12 @@ +--- +yamllint: + description: YAML linter + include: + - comm/ + extensions: ['yml', 'yaml'] + support-files: + - '**/.yamllint' + - 'tools/lint/yamllint_/**' + type: external + payload: commlint:lint_wrapper + wraps: yamllint_:lint |