mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
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.)
This commit is contained in:
parent
8ec1dfde49
commit
de36b2aaba
205 changed files with 40024 additions and 31859 deletions
|
@ -13,11 +13,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { buildGetDocumentParams } from './test_utils';
|
||||
import { EventBus } from '../../web/ui_utils';
|
||||
import { getDocument } from '../../src/display/api';
|
||||
import { PDFFindController } from '../../web/pdf_find_controller';
|
||||
import { SimpleLinkService } from '../../web/pdf_link_service';
|
||||
import { buildGetDocumentParams } from "./test_utils";
|
||||
import { EventBus } from "../../web/ui_utils";
|
||||
import { getDocument } from "../../src/display/api";
|
||||
import { PDFFindController } from "../../web/pdf_find_controller";
|
||||
import { SimpleLinkService } from "../../web/pdf_link_service";
|
||||
|
||||
class MockLinkService extends SimpleLinkService {
|
||||
constructor() {
|
||||
|
@ -44,12 +44,12 @@ class MockLinkService extends SimpleLinkService {
|
|||
}
|
||||
}
|
||||
|
||||
describe('pdf_find_controller', function() {
|
||||
describe("pdf_find_controller", function() {
|
||||
let eventBus;
|
||||
let pdfFindController;
|
||||
|
||||
beforeEach(function(done) {
|
||||
const loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
||||
const loadingTask = getDocument(buildGetDocumentParams("tracemonkey.pdf"));
|
||||
loadingTask.promise.then(function(pdfDocument) {
|
||||
eventBus = new EventBus();
|
||||
|
||||
|
@ -71,9 +71,9 @@ describe('pdf_find_controller', function() {
|
|||
pdfFindController = null;
|
||||
});
|
||||
|
||||
function testSearch({ parameters, matchesPerPage, selectedMatch, }) {
|
||||
function testSearch({ parameters, matchesPerPage, selectedMatch }) {
|
||||
return new Promise(function(resolve) {
|
||||
pdfFindController.executeCommand('find', parameters);
|
||||
pdfFindController.executeCommand("find", parameters);
|
||||
|
||||
// The `updatefindmatchescount` event is only emitted if the page contains
|
||||
// at least one match for the query, so the last non-zero item in the
|
||||
|
@ -98,32 +98,36 @@ describe('pdf_find_controller', function() {
|
|||
return a + b;
|
||||
});
|
||||
|
||||
eventBus.on('updatefindmatchescount',
|
||||
function onUpdateFindMatchesCount(evt) {
|
||||
eventBus.on("updatefindmatchescount", function onUpdateFindMatchesCount(
|
||||
evt
|
||||
) {
|
||||
if (pdfFindController.pageMatches.length !== totalPages) {
|
||||
return;
|
||||
}
|
||||
eventBus.off('updatefindmatchescount', onUpdateFindMatchesCount);
|
||||
eventBus.off("updatefindmatchescount", onUpdateFindMatchesCount);
|
||||
|
||||
expect(evt.matchesCount.total).toBe(totalMatches);
|
||||
for (let i = 0; i < totalPages; i++) {
|
||||
expect(pdfFindController.pageMatches[i].length)
|
||||
.toEqual(matchesPerPage[i]);
|
||||
expect(pdfFindController.pageMatches[i].length).toEqual(
|
||||
matchesPerPage[i]
|
||||
);
|
||||
}
|
||||
expect(pdfFindController.selected.pageIdx)
|
||||
.toEqual(selectedMatch.pageIndex);
|
||||
expect(pdfFindController.selected.matchIdx)
|
||||
.toEqual(selectedMatch.matchIndex);
|
||||
expect(pdfFindController.selected.pageIdx).toEqual(
|
||||
selectedMatch.pageIndex
|
||||
);
|
||||
expect(pdfFindController.selected.matchIdx).toEqual(
|
||||
selectedMatch.matchIndex
|
||||
);
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('performs a normal search', function(done) {
|
||||
it("performs a normal search", function(done) {
|
||||
testSearch({
|
||||
parameters: {
|
||||
query: 'Dynamic',
|
||||
query: "Dynamic",
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
|
@ -137,13 +141,13 @@ describe('pdf_find_controller', function() {
|
|||
}).then(done);
|
||||
});
|
||||
|
||||
it('performs a normal search and finds the previous result', function(done) {
|
||||
it("performs a normal search and finds the previous result", function(done) {
|
||||
// Page 14 (with page index 13) contains five results. By default, the
|
||||
// first result (match index 0) is selected, so the previous result
|
||||
// should be the fifth result (match index 4).
|
||||
testSearch({
|
||||
parameters: {
|
||||
query: 'conference',
|
||||
query: "conference",
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
|
@ -157,10 +161,10 @@ describe('pdf_find_controller', function() {
|
|||
}).then(done);
|
||||
});
|
||||
|
||||
it('performs a case sensitive search', function(done) {
|
||||
it("performs a case sensitive search", function(done) {
|
||||
testSearch({
|
||||
parameters: {
|
||||
query: 'Dynamic',
|
||||
query: "Dynamic",
|
||||
caseSensitive: true,
|
||||
entireWord: false,
|
||||
phraseSearch: true,
|
||||
|
@ -174,12 +178,12 @@ describe('pdf_find_controller', function() {
|
|||
}).then(done);
|
||||
});
|
||||
|
||||
it('performs an entire word search', function(done) {
|
||||
it("performs an entire word search", function(done) {
|
||||
// Page 13 contains both 'Government' and 'Governmental', so the latter
|
||||
// should not be found with entire word search.
|
||||
testSearch({
|
||||
parameters: {
|
||||
query: 'Government',
|
||||
query: "Government",
|
||||
caseSensitive: false,
|
||||
entireWord: true,
|
||||
phraseSearch: true,
|
||||
|
@ -193,12 +197,12 @@ describe('pdf_find_controller', function() {
|
|||
}).then(done);
|
||||
});
|
||||
|
||||
it('performs a multiple term (no phrase) search', function(done) {
|
||||
it("performs a multiple term (no phrase) search", function(done) {
|
||||
// Page 9 contains 'alternate' and pages 6 and 9 contain 'solution'.
|
||||
// Both should be found for multiple term (no phrase) search.
|
||||
testSearch({
|
||||
parameters: {
|
||||
query: 'alternate solution',
|
||||
query: "alternate solution",
|
||||
caseSensitive: false,
|
||||
entireWord: false,
|
||||
phraseSearch: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue