Commit Graph

28 Commits

Author SHA1 Message Date
Jonas Jenwald
1fc09f0235 Enable the unicorn/prefer-string-replace-all ESLint plugin rule
Note that the `replaceAll` method still requires that a *global* regular expression is used, however by using this method it's immediately obvious when looking at the code that all occurrences will be replaced; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#parameters

Please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-replace-all.md
2023-03-23 12:57:10 +01:00
Jonas Jenwald
5f64621d46 Use String.prototype.replaceAll() where appropriate
This fairly new method allows replacing *multiple* occurrences within a string without having to use regular expressions.

Please refer to:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#browser_compatibility
2023-03-22 15:31:10 +01:00
Jonas Jenwald
96d2a2f795 Enable the ESLint no-var rule in the external/ folder
These changes were done automatically, by using the `gulp lint --fix` command.
2021-03-14 11:43:25 +01:00
Jonas Jenwald
2ffa428d78 Enable the ESLint no-var rule in the importL10n/ folder 2021-03-13 17:23:41 +01:00
Jonas Jenwald
426945b480 Update Prettier to version 2.0
Please note that these changes were done automatically, using `gulp lint --fix`.

Given that the major version number was increased, there's a fair number of (primarily whitespace) changes; please see https://prettier.io/blog/2020/03/21/2.0.0.html
In order to reduce the size of these changes somewhat, this patch maintains the old "arrowParens" style for now (once mozilla-central updates Prettier we can simply choose the same formatting, assuming it will differ here).
2020-04-14 12:28:14 +02:00
Jonas Jenwald
de36b2aaba Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).

Prettier is being used for a couple of reasons:

 - To be consistent with `mozilla-central`, where Prettier is already in use across the tree.

 - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.

Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.

*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.

(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-26 12:34:24 +01:00
Jonas Jenwald
8852991c60 Simplify the handling of EXCLUDE_LANG_CODES (PR 11213 follow-up) 2019-10-26 13:49:37 +02:00
Jonas Jenwald
0a17fca46e Ensure that we'll never, accidentally, try and fetch the default en-US locale (PR 11213 follow-up) 2019-10-19 18:00:15 +02:00
Jonas Jenwald
b663cec383 [Firefox] Stop fetching the chrome.properties files during gulp importl10n (PR 9566 follow-up)
With the removal of the (standalone) Firefox building code in PR 9566 (a year and a half ago), these files are now completely unused in the GitHub repository[1].
Hence it doesn't really seem necessary to keep fetching them with `gulp importl10n`, and the existing files in the `l10n` folder can also be removed (thanks to version control, they're easy enough to restore should the need ever arise).

The patch also allows an additional simplification, for the `gulp locale` and `gulp mozcentral` commands, since it's now possible to stop writing `l10n` files to the `extensions/firefox/` folder and instead just copy them similar to other build targets.

---
[1] They're obviously still used in `mozilla-central`, for fallback messages displayed through `PdfStreamConverter.jsm`, but that doesn't make it necessary to keep them *here* as far as I'm concerned.
2019-10-17 12:27:11 +02:00
Jonas Jenwald
dee3da69d4 Have gulp importl10n list locales which may be candidates for removal
Rather than having the script remove locales automatically, which seems like a heavy-handed approach at least initially, listing these for manual checking seems nice though.
2019-10-06 18:12:29 +02:00
Jonas Jenwald
ed71ec3785 Update the gulp importl10n command to fetch the active language codes
Rather than having to manually maintain a static list of language codes, it's much easier to simply fetch the active ones from `mozilla-central` instead.

As part of this the code in `external/importL10n/locales.js` was modernized slightly, by using Promises/async functions to get rid of a bunch of annoying callbacks (which shouldn't be a problem for reasonably modern Node.js versions).
2019-10-06 18:12:27 +02:00
Tim van der Meij
bdd28fd717
Remove unmaintained localizations
Fixes #11167.
2019-09-21 13:31:42 +02:00
Tim van der Meij
8a6b7373a0
Remove the jp-JP-mac locale
It gives warnings when running `gulp locale`, in a previous patch it was
explicitly asked to remove it and there is quite a bit of discussion
about the validity of the locale at
https://bugzilla.mozilla.org/show_bug.cgi?id=418485. In short, let's
remove it to prevent these issues.
2018-07-08 15:40:38 +02:00
Tim van der Meij
5baec1eeb4
Update translations 2018-06-30 20:36:17 +02:00
Tim van der Meij
2247af7e95
Update translations
This required changing the import script in two ways:

- we should use the `default` branch and not the `tip` tag since the
  latter may refer to another branch than `default` (this is the case for
  the `vi` locale, which caused in the files to be overwritten with
  incorrect contents since `tip` referred to the
  `THUNDERBIRD600b1_2018031614_RELBRANCH` branch);
- we should check if the response code is indeed 200 because recently a
  script removed all empty localization files upstream (refer to
  https://bugzilla.mozilla.org/show_bug.cgi?id=1443175).
2018-03-17 16:31:04 +01:00
Jonas Jenwald
957dc40ddf Replace a couple of leftover make.js references with gulpfile.js in docs/comments
Also updates a `console.log` statement in the `gulp importl10n` command (since I forgot it in a previous patch, and it didn't seem necessary with a separate patch for it).
2017-05-19 23:45:54 +02:00
Jonas Jenwald
044a115d6e Change the importl10n script to use the Nightly channel
It seems that PR 8323 unfortunately didn't pick the right channel for pulling translations from, according to the information in:
 - https://groups.google.com/forum/#!topic/mozilla.dev.l10n/vzmbHLPo3rg
 - https://github.com/mozilla-l10n/localizer-documentation/blob/master/misc/aurora_faqs.md

My apologies for the unnecessary churn in this code!
2017-05-18 12:35:05 +02:00
Jonas Jenwald
57cd52303a Change the importl10n script to use the Beta channel, since Aurora is being removed
Since the Aurora channel is being removed, and is no longer going to be receiving updates (with the possible exception of security bugs), we need to change the target for the `gulp importl10n` command.

For more information, please refer to:
 - https://groups.google.com/forum/#!topic/firefox-dev/q4Eb5nEcfSg
 - https://hacks.mozilla.org/2017/04/simplifying-firefox-release-channels/
 - https://mozilla.github.io/process-releases/draft/development_overview/
 - http://release.mozilla.org/firefox/release/2017/04/17/Dawn-Project-FAQ.html
2017-04-22 16:24:52 +02:00
Jonas Jenwald
52e0f51917 Enable the no-unused-vars ESLint rule
Please see http://eslint.org/docs/rules/no-unused-vars; note that this patch purposely uses the same rule options as in `mozilla-central`, such that it fixes part of issue 7957.

It wasn't, in my opinion, entirely straightforward to enable this rule compared to the already existing rules. In many cases a `var descriptiveName = ...` format was used (more or less) to document the code, and I choose to place the old variable name in a trailing comment to not lose that information.

I welcome feedback on these changes, since it wasn't always entirely easy to know what changes made the most sense in every situation.
2017-01-29 23:23:17 +01:00
Jonas Jenwald
2f3805efbc Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*

ESLint has a number of advantageous properties, compared to JSHint. Among those are:
 - The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
 - Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
 - Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
 - The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
 - More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.

By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.

I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.

Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).

A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
 - `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
 - `object-curly-spacing`, controls spacing inside of Objects.
 - `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)

Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.

Useful links:
 - http://eslint.org/docs/user-guide/configuring
 - http://eslint.org/docs/rules/
2016-12-16 21:06:36 +01:00
Tim van der Meij
978b214c92 Lint: do not ignore external/importL10n as it is one of our components 2016-11-01 14:43:38 +01:00
Jonas Jenwald
bd0affab9c Unbreak the importl10n command by updating the links to point to hg.mozilla.org instead of mxr
Currently `importl10n` fails, since mxr.mozilla.org has been down for a while. Based on discussions in #developers, it isn't clear to me if/when it'll be available again.
Furthermore, I'm not sure why we're even getting the l10n files through a code search tool, rather than just using the official Mozilla repository directly.
2016-06-22 09:41:11 +02:00
Yury Delendik
76aa687548 Makes importl10n and server async gulp functions. 2016-04-22 17:23:25 -05:00
Jonas Jenwald
41e5fa3c7a Use the correct path when checking if a /l10n directory exists, to avoid errors during gulp importl10n (PR 7063 followup)
This is regression from PR 7063, causing `gulp importl10n` to fail:
```
$ gulp importl10n
[19:45:02] Using gulpfile c:\Users\Jonas\Git\pdfjs\gulpfile.js
[19:45:02] Starting 'importl10n'...

Downloading ach...
[19:45:02] 'importl10n' errored after 4.42 ms
[19:45:02] Error: EEXIST, file already exists 'c:\Users\Jonas\Git\pdfjs\l10n\ach
'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:747:18)
    at downloadLanguageFiles (c:\Users\Jonas\Git\pdfjs\external\importL10n\local
es.js:59:8)
    at next (c:\Users\Jonas\Git\pdfjs\external\importL10n\locales.js:90:5)
    at Object.downloadL10n (c:\Users\Jonas\Git\pdfjs\external\importL10n\locales
.js:91:5)
    at Gulp.<anonymous> (c:\Users\Jonas\Git\pdfjs\gulpfile.js:92:11)
    at module.exports (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\node_modules\o
rchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\no
de_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\no
de_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\node_
modules\orchestrator\index.js:134:8)
```
2016-03-20 20:02:43 +01:00
Tim van der Meij
96cca2b37a Migrate clean and importl10n target to gulp 2016-03-04 21:14:56 +01:00
Manas
a2ba1b8189 Uses editorconfig to maintain consistent coding styles
Removes the following as they unnecessary
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-11-14 07:32:18 +05:30
Yury Delendik
812c5accb2 Making sure we are not importing CRs and BOMs 2014-05-28 08:25:27 -05:00
Tim van der Meij
c6f009403d Implements importl10n command 2014-03-26 23:48:02 +01:00