[gjs: 1/7] format: Add some linter rules and warnings about imports.format
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/7] format: Add some linter rules and warnings about imports.format
- Date: Tue, 9 Feb 2021 03:30:22 +0000 (UTC)
commit 53603db3dd42e0e2c86bedaa3a5fbcfdeefadfb9
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Aug 15 12:20:31 2020 -0700
format: Add some linter rules and warnings about imports.format
Also pkg.initFormat() which patches the global String.prototype.
These are not deprecated as such, because Format.vprintf can still be
necessary when interacting with gettext in some cases, but it is
definitely discouraged to monkeypatch the global String prototype.
.eslintrc.yml | 6 ++++++
doc/Package/Specification.md | 3 +--
installed-tests/js/testFormat.js | 1 +
modules/script/package.js | 1 +
4 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 0a07f205..0aa6acf2 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -124,6 +124,12 @@ rules:
no-restricted-globals: [error, window]
no-restricted-properties:
- error
+ - object: imports
+ property: format
+ message: Use template strings
+ - object: pkg
+ property: initFormat
+ message: Use template strings
- object: Lang
property: copyProperties
message: Use Object.assign()
diff --git a/doc/Package/Specification.md b/doc/Package/Specification.md
index 41aac732..ec02a688 100644
--- a/doc/Package/Specification.md
+++ b/doc/Package/Specification.md
@@ -96,7 +96,6 @@ The following API will be available to applications, through the [`package.js`](
* `pkg.prefix`, `pkg.datadir`, `pkg.libdir` will return the installed locations of those folders
* `pkg.pkgdatadir`, `pkg.moduledir`, `pkg.pkglibdir`, `pkg.localedir` will return the respective
directories, or the appropriate subdirectory of the current directory if running uninstalled
* `pkg.initGettext()` will initialize gettext. After calling `globalThis._`, `globalThis.C_` and
`globalThis.N_` will be available
-* `pkg.initFormat()` will initialize the format module. After calling, String.prototype.format will be
available
* `pkg.initSubmodule(name)` will initialize a submodule named @name. It must be called before accessing the
typelibs installed by that submodule
* `pkg.loadResource(name)` will load and register a GResource named @name. @name is optional and defaults to
${package-name}
-* `pkg.require(deps)` will mark a set of dependencies on GI and standard JS modules. **@deps** is a object
whose keys are repository names and whose values are API versions. If the dependencies are not satisfied,
`pkg.require()` will print an error message and quit.
\ No newline at end of file
+* `pkg.require(deps)` will mark a set of dependencies on GI and standard JS modules. **@deps** is a object
whose keys are repository names and whose values are API versions. If the dependencies are not satisfied,
`pkg.require()` will print an error message and quit.
diff --git a/installed-tests/js/testFormat.js b/installed-tests/js/testFormat.js
index 6e46e420..c8f4fc07 100644
--- a/installed-tests/js/testFormat.js
+++ b/installed-tests/js/testFormat.js
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2013 Red Hat, Inc.
+// eslint-disable-next-line no-restricted-properties
const Format = imports.format;
String.prototype.format = Format.format;
diff --git a/modules/script/package.js b/modules/script/package.js
index 28cfe542..11465997 100644
--- a/modules/script/package.js
+++ b/modules/script/package.js
@@ -306,6 +306,7 @@ function initGettext() {
}
function initFormat() {
+ // eslint-disable-next-line no-restricted-properties
let format = imports.format;
String.prototype.format = format.format;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]