Commit Graph

98 Commits

Author SHA1 Message Date
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
Jonas Jenwald
28e50cfa21 Fix errors reported by the space-infix-ops ESLint rule
http://eslint.org/docs/rules/space-infix-ops
2016-12-12 20:36:00 +01:00
Jonas Jenwald
aae27e76bb Fix errors reported by the no-multiple-empty-lines ESLint rule
http://eslint.org/docs/rules/no-multiple-empty-lines
2016-12-12 20:35:58 +01:00
Jonas Jenwald
6606540fe4 Fix errors reported by the func-call-spacing ESLint rule
http://eslint.org/docs/rules/func-call-spacing
2016-12-12 20:35:54 +01:00
Yury Delendik
a4402c84de Refactor toolbar (and secondary toolbar). 2016-11-18 12:51:15 -06:00
Jonas Jenwald
4f1cccb138 Enable removing of all comments (except for Copyright notices) when preprocessing code, and reduce the indentation level 2016-11-11 22:05:17 +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
Yury Delendik
bf52ff156d Adds esprima-based preprocessor. 2016-10-14 08:33:22 -05: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
a4c81c203b Enables debugger only when needed. 2016-05-09 18:18:43 -05:00
Yury Delendik
fe6001363d Moves all testing into gulpfile. 2016-05-02 09:58:29 -05:00
Yury Delendik
76aa687548 Makes importl10n and server async gulp functions. 2016-04-22 17:23:25 -05:00
Yury Delendik
006e8fb59d Introduces UMD headers to the web/ folder. 2016-04-13 10:09:48 -05:00
Yury Delendik
118b71925c Forces UMD header to have relative path and extension for CommonJS. 2016-04-02 11:10:36 -05:00
Yury Delendik
0a700fa29d Updates Jasmine version. 2016-03-29 09:34:13 -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
Yury Delendik
cbbb9bb82d Adds UMD header to pdf.js and pdf.worker.js files. 2015-12-29 18:15:14 -06:00
Yury Delendik
fc3282db56 Adds RequireJS to worker. 2015-12-29 09:20:52 -06:00
Yury Delendik
85e95d34ed Use RequireJS in the viewer, examples and tests. 2015-12-29 09:20:52 -06:00
Tim van der Meij
df81b832bb Remove unused variables 2015-12-16 23:52:16 +01:00
Yury Delendik
450edc95cc UMD validation and generation tools. 2015-12-15 13:24:39 -06: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
Rob Wu
f8af4d6567 Fix preprocessor: nesting, error & tests
Features / bug fixes in the preprocessor:

- Add word boundary after regex for preprocessor token matching.
  Previously, when you mistakenly used "#ifdef" instead of "#if", the
  line would be parsed as a preprocessor directive (because "#ifdef"
  starts with "#if"), but without condition (because "def" does not
  start with a space). Consequently, the condition would always be false
  and anything between "#ifdef" and "#endif" would not be included.

- Add validation and error reporting everywhere, to aid debugging.

- Support nested comments (by accounting for the whole stack of
  conditions, instead of only the current one).

- Add #elif preprocessor command. Could be used as follows:
  //#if !FEATURE_ENABLED
  //#error FEATURE_ENABLED must be set
  //#endif

- Add #error preprocessor command.

- Add end-of-line word boundary after "-->" in the comment trimmer.
  Otherwise the pattern would also match "-->" in the middle of a line,
  and incorrectly convert something like "while(i-->0)" to "while(i0)".

Code health:

- Add unit tests for the preprocessor (run external/builder/test.js).

- Fix broken link to MDN (resolved to DXR).

- Refactor to use STATE_* names instead of magic numbers (the original
  meaning of the numbers is preserved, with one exception).

- State 3 has been split in two states, to distinguish between being in
  an #if and #else. This is needed to ensure that #else cannot be
  started without an #if.
2015-07-19 14:47:28 +02:00
Rob Wu
8ba73cb4de Improve getWorkerSrcFiles (builder.js)
It took a while to figure out why adding comments in worker_loader.js
caused the build to fail, because getWorkerSrcFiles did not print an
error message when it failed to parse the file. These issues have been
resolved as follows:

- Leading comments are stripped.
- The trailing comma is removed from the array.
- Errors are detected and useful error messages are printed.
2015-07-19 14:47:28 +02:00
Mike Corbin
979c108577 Remove unused require() directive
This had the undesirable side-effect of invoking make's command-line argument
parser upon inclusion.
2015-05-15 18:01:33 +01:00
Tim van der Meij
70b6eb09a8 Remove ShellJS copy and use the NPM version
There is no need to have a copy of ShellJS in the repository as it is also available on NPM. The NPM version is also much newer. This way we do not have to update this anymore and let NPM do that automatically.
2015-04-05 15:47:25 +02:00
Tim van der Meij
0ab5bb4b42 Fixes minor typo from #5826 2015-03-11 21:09:03 +01:00
Rob Wu
537216b872 [webL10n] Apply PDF.js-specific changes 2015-03-10 16:13:25 +01:00
Rob Wu
f20c5ddf99 Update to latest version of webL10n
New commits since last update:
- b5e072c...7d351d51b1
- Plus unmerged patch from PDF.js: https://github.com/fabi1cazenave/webL10n/pull/62

(the PDF.js-specific changes will be applied in a separate commit)
2015-03-10 16:11:59 +01:00
Rob Wu
ac5a8bcdda [l10n] Treat language as case-insensitive
See "Case-insensitive language comparisons per RFC 4646"
https://github.com/fabi1cazenave/webL10n/pull/51

Removed the "patch" in compatibility.js and fixed the bug in webL10n,
because the logic belongs to webL10n instead of PDF.js.
The immediate motivation for this patch is that Chrome 40 converts
navigator.language to lower case: https://crbug.com/454331
2015-02-02 22:02:18 +01:00
araghava
e2c001c19d [issue 5440] fix rtl direction bug for full language codes 2014-10-26 17:16:56 -04:00
Yury Delendik
5b93cc102c Adds css import preprocessing 2014-09-30 08:11:43 -05:00
Yury Delendik
10f702f60e Adds readme file for the pdfjs-dist repo. 2014-09-24 07:10:09 -05:00
Tim van der Meij
c29faaa22d Use strict equalities in make.js, external/* and extensions/* 2014-08-01 22:27:00 +02:00
Yury Delendik
812c5accb2 Making sure we are not importing CRs and BOMs 2014-05-28 08:25:27 -05:00
Tim van der Meij
a762c9f3c6 Removing old TODOs and comments from jasmine.js 2014-05-08 22:45:30 +02:00
Thorben Bochenek
e8f0700bfa Move the colour conversion to jpg.js
Benchmarking shows that this improves performance for the invitation document
from https://github.com/mozilla/pdf.js/issues/3809 by 35%
2014-04-24 15:07:12 +02:00
Thorben Bochenek
e7fe45a5c4 Refactor jpg.js and include forceRGBoutput, correct style of image.js
This refactors getData to be more readable and extracts all the color
conversion algorithms to their own functions. The resulting code was then
cleaned up.
This also introduces a flag `forceRGBoutput` to getData, that allows to always
get the data as a `width * height * 3` bytes long RGB buffer
2014-04-24 12:55:37 +02:00
Christian Krebs
5a49d2eb83 Create the WORKER_SRC_FILES and EXT_SRC_FILES lists in make automatically 2014-04-09 21:02:13 +02:00
Yury Delendik
5fc806823e Merge pull request #4504 from timvandermeij/importl10n
Import l10n files from mozilla-aurora
2014-03-26 17:52:45 -05:00
Tim van der Meij
c6f009403d Implements importl10n command 2014-03-26 23:48:02 +01:00
Thorben Bochenek
7bf0987810 Fixes for small colour variations in tests
https://github.com/notmasteryet/jpgjs/pull/24
2014-03-25 19:04:02 -05:00
Thorben Bochenek
2d99ff3f37 Fix for the offByOne-error and small performance optimisations 2014-03-21 09:16:40 -05:00
Thorben Bochenek
03892a85c2 jpgjs performance improvements
see https://github.com/notmasteryet/jpgjs/pull/22
2014-03-20 18:02:08 -05:00
Brendan Dahl
68be273c69 Merge pull request #4470 from yurydelendik/packcmap
CMaps binary packing
2014-03-17 12:27:35 -07:00
Yury Delendik
1d8f6cf0e7 Updates make.js for cmaps and make binary cmaps by default 2014-03-17 13:30:43 -05:00
Yury Delendik
734d6f346e Removes external/cmaps; adds binary cmaps to the repo 2014-03-17 13:30:27 -05:00
Yury Delendik
3e8ea958ae Quick notes about the format 2014-03-14 16:59:40 -05:00
Yury Delendik
69efd9cb96 CMaps binary packing 2014-03-14 16:46:35 -05:00