Skip to content

Commit

Permalink
Fix eslint and prettier warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
blikblum committed Sep 9, 2020
1 parent e05e89b commit 326350b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
19 changes: 11 additions & 8 deletions docs/generate_website.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Please pipe the document into a Node stream.\
}
}

_finalize(fn) {
_finalize() {
// generate xref
const xRefOffset = this._offset;
this._write('xref');
Expand Down
3 changes: 0 additions & 3 deletions lib/mixins/acroform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 6 additions & 2 deletions lib/mixins/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
Expand Down
22 changes: 15 additions & 7 deletions lib/name_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -20,21 +19,30 @@ 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('>>');
return out.join('\n');
}
}

export default PDFNameTree;
export default PDFNameTree;
7 changes: 5 additions & 2 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 =
Expand Down
24 changes: 12 additions & 12 deletions lib/saslprep/lib/code-points.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1100,15 +1100,15 @@ const prohibited_characters = [
0x100000,
0x10fffd /* [PRIVATE USE, PLANE 16] */
];
/* eslint-enable */
// prettier-ignore-end

const isProhibitedCharacter = character =>
inRange(character, non_ASCII_space_characters) ||
inRange(character, prohibited_characters) ||
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1914,7 +1914,7 @@ const bidirectional_l = [
0x100000,
0x10fffd
];
/* eslint-enable */
// prettier-ignore-end

const isBidirectionalL = character => inRange(character, bidirectional_l);

Expand Down
1 change: 1 addition & 0 deletions lib/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/acroform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 326350b

Please sign in to comment.