diff --git a/docs/generate.js b/docs/generate.js index 2f3ba6e56..59cbeb4b5 100644 --- a/docs/generate.js +++ b/docs/generate.js @@ -286,7 +286,7 @@ const render = (doc, filename) => { }; // renders the title page of the guide -const renderTitlePage = (doc) => { +const renderTitlePage = doc => { const title = 'PDFKit Guide'; const author = 'By Devon Govett'; const version = `Version ${require('../package.json').version}`; diff --git a/docs/generate_website.js b/docs/generate_website.js index 07a503c2d..8323dd0f7 100644 --- a/docs/generate_website.js +++ b/docs/generate_website.js @@ -87,15 +87,18 @@ const generateImages = function(tree) { // write the PDF, convert to PNG and trim with ImageMagick (https://imagemagick.org) file.on('finish', () => { - exec(`magick convert -density 150x150 -trim ${f}.pdf ${f}.png`, (err, stdout, stderr) => { - if (stderr) { - console.error(stderr); + exec( + `magick convert -density 150x150 -trim ${f}.pdf ${f}.png`, + (err, stdout, stderr) => { + if (stderr) { + console.error(stderr); + } + if (err) { + console.error(err); + } + fs.unlinkSync(`${f}.pdf`); } - if (err) { - console.error(err); - } - fs.unlinkSync(`${f}.pdf`); - }); + ); }); doc.end(); diff --git a/lib/document.js b/lib/document.js index 6f0e3b516..d75e56abe 100644 --- a/lib/document.js +++ b/lib/document.js @@ -285,7 +285,7 @@ Please pipe the document into a Node stream.\ } } - _finalize(fn) { + _finalize() { // generate xref const xRefOffset = this._offset; this._write('xref'); diff --git a/lib/mixins/acroform.js b/lib/mixins/acroform.js index 755c9d1ee..4df990fb5 100644 --- a/lib/mixins/acroform.js +++ b/lib/mixins/acroform.js @@ -361,9 +361,6 @@ export default { options.Opt = select; } - if (options.value || options.defaultValue) { - let x = 0; - } Object.keys(VALUE_MAP).forEach(key => { if (options[key] !== undefined) { options[VALUE_MAP[key]] = options[key]; diff --git a/lib/mixins/vector.js b/lib/mixins/vector.js index c0a3d623a..226a0940c 100644 --- a/lib/mixins/vector.js +++ b/lib/mixins/vector.js @@ -68,8 +68,12 @@ export default { } const valid = length.every(x => Number.isFinite(x) && x > 0); - if(!valid) { - throw new Error(`dash(${JSON.stringify(originalLength)}, ${JSON.stringify(options)}) invalid, lengths must be numeric and greater than zero`); + if (!valid) { + throw new Error( + `dash(${JSON.stringify(originalLength)}, ${JSON.stringify( + options + )}) invalid, lengths must be numeric and greater than zero` + ); } length = length.map(number).join(' '); diff --git a/lib/name_tree.js b/lib/name_tree.js index fcb446d22..c3e423bb8 100644 --- a/lib/name_tree.js +++ b/lib/name_tree.js @@ -5,13 +5,12 @@ PDFNameTree - represents a name tree object import PDFObject from './object'; class PDFNameTree { - constructor() { this._items = {}; } add(key, val) { - return this._items[key] = val; + return (this._items[key] = val); } get(key) { @@ -20,16 +19,25 @@ class PDFNameTree { toString() { // Needs to be sorted by key - const sortedKeys = (Object.keys(this._items)).sort((a, b) => a.localeCompare(b)); + const sortedKeys = Object.keys(this._items).sort((a, b) => + a.localeCompare(b) + ); const out = ['<<']; if (sortedKeys.length > 1) { - const first = sortedKeys[0], last = sortedKeys[sortedKeys.length - 1]; - out.push(` /Limits ${PDFObject.convert([new String(first), new String(last)])}`); + const first = sortedKeys[0], + last = sortedKeys[sortedKeys.length - 1]; + out.push( + ` /Limits ${PDFObject.convert([new String(first), new String(last)])}` + ); } out.push(' /Names ['); for (let key of sortedKeys) { - out.push(` ${PDFObject.convert(new String(key))} ${PDFObject.convert(this._items[key])}`); + out.push( + ` ${PDFObject.convert(new String(key))} ${PDFObject.convert( + this._items[key] + )}` + ); } out.push(']'); out.push('>>'); @@ -37,4 +45,4 @@ class PDFNameTree { } } -export default PDFNameTree; \ No newline at end of file +export default PDFNameTree; diff --git a/lib/object.js b/lib/object.js index 3f50359bf..c92461bc6 100644 --- a/lib/object.js +++ b/lib/object.js @@ -8,7 +8,7 @@ import PDFNameTree from './name_tree'; const pad = (str, length) => (Array(length + 1).join('0') + str).slice(-length); -const escapableRe = /[\n\r\t\b\f\(\)\\]/g; +const escapableRe = /[\n\r\t\b\f()\\]/g; const escapable = { '\n': '\\n', '\r': '\\r', @@ -77,7 +77,10 @@ class PDFObject { // Buffers are converted to PDF hex strings } else if (Buffer.isBuffer(object)) { return `<${object.toString('hex')}>`; - } else if (object instanceof PDFAbstractReference || object instanceof PDFNameTree) { + } else if ( + object instanceof PDFAbstractReference || + object instanceof PDFNameTree + ) { return object.toString(); } else if (object instanceof Date) { let string = diff --git a/lib/saslprep/lib/code-points.js b/lib/saslprep/lib/code-points.js index 189050cae..fbe07e573 100644 --- a/lib/saslprep/lib/code-points.js +++ b/lib/saslprep/lib/code-points.js @@ -1,6 +1,6 @@ import { inRange } from './util'; -/* eslint-disable prettier/prettier */ +// prettier-ignore-start /** * A.1 Unassigned code points in Unicode 3.2 * @link https://tools.ietf.org/html/rfc3454#appendix-A.1 @@ -799,12 +799,12 @@ const unassigned_code_points = [ 0xe0080, 0xefffd ]; -/* eslint-enable */ +// prettier-ignore-end const isUnassignedCodePoint = character => inRange(character, unassigned_code_points); -/* eslint-disable prettier/prettier */ +// prettier-ignore-start /** * B.1 Commonly mapped to nothing * @link https://tools.ietf.org/html/rfc3454#appendix-B.1 @@ -865,12 +865,12 @@ const commonly_mapped_to_nothing = [ 0xfeff, 0xfeff ]; -/* eslint-enable */ +// prettier-ignore-end const isCommonlyMappedToNothing = character => inRange(character, commonly_mapped_to_nothing); -/* eslint-disable prettier/prettier */ +// prettier-ignore-start /** * C.1.2 Non-ASCII space characters * @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2 @@ -911,12 +911,12 @@ const non_ASCII_space_characters = [ 0x3000, 0x3000 /* IDEOGRAPHIC SPACE */ ]; -/* eslint-enable */ +// prettier-ignore-end const isNonASCIISpaceCharacter = character => inRange(character, non_ASCII_space_characters); -/* eslint-disable prettier/prettier */ +// prettier-ignore-start const non_ASCII_controls_characters = [ /** * C.2.2 Non-ASCII control characters @@ -1100,7 +1100,7 @@ const prohibited_characters = [ 0x100000, 0x10fffd /* [PRIVATE USE, PLANE 16] */ ]; -/* eslint-enable */ +// prettier-ignore-end const isProhibitedCharacter = character => inRange(character, non_ASCII_space_characters) || @@ -1108,7 +1108,7 @@ const isProhibitedCharacter = character => inRange(character, non_ASCII_controls_characters) || inRange(character, non_character_codepoints); -/* eslint-disable prettier/prettier */ +// prettier-ignore-start /** * D.1 Characters with bidirectional property "R" or "AL" * @link https://tools.ietf.org/html/rfc3454#appendix-D.1 @@ -1183,11 +1183,11 @@ const bidirectional_r_al = [ 0xfe76, 0xfefc ]; -/* eslint-enable */ +// prettier-ignore-end const isBidirectionalRAL = character => inRange(character, bidirectional_r_al); -/* eslint-disable prettier/prettier */ +// prettier-ignore-start /** * D.2 Characters with bidirectional property "L" * @link https://tools.ietf.org/html/rfc3454#appendix-D.2 @@ -1914,7 +1914,7 @@ const bidirectional_l = [ 0x100000, 0x10fffd ]; -/* eslint-enable */ +// prettier-ignore-end const isBidirectionalL = character => inRange(character, bidirectional_l); diff --git a/lib/security.js b/lib/security.js index 80d7e550f..e5421cc45 100644 --- a/lib/security.js +++ b/lib/security.js @@ -11,6 +11,7 @@ class PDFSecurity { let infoStr = `${info.CreationDate.getTime()}\n`; for (let key in info) { + // eslint-disable-next-line no-prototype-builtins if (!info.hasOwnProperty(key)) { continue; } diff --git a/tests/unit/acroform.spec.js b/tests/unit/acroform.spec.js index 863338006..4c1db5f7c 100644 --- a/tests/unit/acroform.spec.js +++ b/tests/unit/acroform.spec.js @@ -66,7 +66,7 @@ describe('acroform', () => { test('init no fonts', () => { doc.addPage(); const docData = logData(doc); - const font = PDFFontFactory.open(doc, 'tests/fonts/Roboto-Regular.ttf'); + PDFFontFactory.open(doc, 'tests/fonts/Roboto-Regular.ttf'); doc.initForm(); expect(docData.length).toBe(0); });