Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ of `@signpdf/signpdf`
- `$ yarn workspace @signpdf/signpdf add @signpdf/some-new-subpackage@* -D` adds a `@signpdf/some-new-subpackage` as a dev dependency of `@signpdf/signpdf`. Note the `@*` version specifier.
- `$ npm publish --access public` is needed the first time a package get published as our packages are scoped and that is private by default. See: https://bit.ly/47ScKPF

## Lint configuration

ESLint 9 uses the root `eslint.config.mjs` for all workspaces. The shared configuration
in `packages/eslint-config` combines ESLint recommended, Stylistic, import, and Jest
presets with a few project overrides. Examples use ESLint's recommended rules.

Run `yarn lint` for all packages or `yarn workspace @signpdf/utils lint` for one
package. Manage ESLint dependencies at the repository root and plugin dependencies
in `packages/eslint-config`.

The root Yarn resolution keeps `typescript-estree` on a patched `minimatch`
release for CVE-2026-118764. Review this override when updating the Jest lint plugin.

## Contributors

* [vbuch](https://github.com/vbuch)
Expand Down
40 changes: 40 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import js from '@eslint/js';
import {defineConfig} from 'eslint/config';
import globals from 'globals';
import sharedConfig from '@signpdf/eslint-config';

const packageFiles = [
'packages/placeholder-pdf-lib/**/*.js',
'packages/placeholder-pdfkit/**/*.js',
'packages/placeholder-pdfkit010/**/*.js',
'packages/placeholder-plain/**/*.js',
'packages/signer-p12/**/*.js',
'packages/signpdf/**/*.js',
'packages/utils/**/*.js',
];

export default defineConfig([
{
ignores: [
'**/node_modules/**',
'**/coverage/**',
'**/dist/**',
'**/jest.config.js',
'**/.*',
],
},
{
files: packageFiles,
extends: [sharedConfig],
},
{
name: 'signpdf/examples',
files: ['packages/examples/**/*.js'],
extends: [js.configs.recommended],
languageOptions: {
ecmaVersion: 2019,
sourceType: 'commonjs',
globals: globals.node,
},
},
]);
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@
"test": "lerna run test"
},
"devDependencies": {
"@eslint/js": "^9.39.5",
"@signpdf/eslint-config": "^3.2.3",
"coveralls": "^3.0.2",
"eslint": "^9.39.5",
"globals": "^17.14.0",
"husky": "^7.0.4",
"lerna": "^7.3.0"
"lerna": "^7.3.0",
"typescript": "^5.2.2"
},
"dependencies": {}
"dependencies": {},
"resolutions": {
"**/@typescript-eslint/typescript-estree/minimatch": "^11.0.5"
}
}
85 changes: 49 additions & 36 deletions packages/eslint-config/eslint.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
module.exports = {
extends: [
"airbnb-base",
"plugin:jest/recommended"
],
env: {
"es6": true,
"node": true,
"jest": true
import js from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';
import {defineConfig} from 'eslint/config';
import {importX, createNodeResolver} from 'eslint-plugin-import-x';
import jest from 'eslint-plugin-jest';
import globals from 'globals';

export default defineConfig([
{
name: '@signpdf/eslint-config/javascript',
extends: [
js.configs.recommended,
stylistic.configs.customize({
indent: 4,
quotes: 'single',
semi: true,
jsx: false,
arrowParens: true,
braceStyle: '1tbs',
}),
importX.flatConfigs.recommended,
],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: globals.node,
},
settings: {
'import-x/resolver-next': [createNodeResolver({
extensions: ['.mjs', '.js', '.json'],
})],
},
rules: {
curly: ['error', 'all'],
'@stylistic/brace-style': ['error', '1tbs', {allowSingleLine: false}],
'@stylistic/object-curly-spacing': ['error', 'never'],
'import-x/no-extraneous-dependencies': ['error', {
devDependencies: ['**/*.test.js', '**/__mocks__/*'],
}],
},
},
parser: "@babel/eslint-parser",
parserOptions: {
requireConfigFile: false
{
name: '@signpdf/eslint-config/tests',
files: ['**/*.test.js'],
extends: [jest.configs['flat/recommended']],
rules: {
'jest/no-conditional-expect': 'off',
'jest/valid-title': ['error', {ignoreTypeOfDescribeName: true}],
},
},
plugins: [
"jest"
],
rules: {
"indent": ["error", 4, { "SwitchCase": 1 }],
"object-curly-spacing": ["error", "never"],
"import/no-extraneous-dependencies": ["error", { "devDependencies": ["**/*.test.js", "**/__mocks__/*"] }],
"func-names": ["warn", "never"],
"no-throw-literal": "off",
"no-console": ["warn", { "allow": ["warn", "error", "info"] }],
"space-before-function-paren": ["error", { "anonymous": "never", "named": "never", "asyncArrow": "always" }],
"radix": ["error", "as-needed"],
"class-methods-use-this": "off",
"jest/no-conditional-expect": "off",
"import/prefer-default-export": "off",
"no-bitwise": "off",
"jest/valid-title": ["error", {"ignoreTypeOfDescribeName": true}]
},
settings: {
"import/resolver": {
"babel-module": {}
}
}
}
]);
11 changes: 11 additions & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
"name": "@signpdf/eslint-config",
"version": "3.2.3",
"description": "",
"type": "module",
"main": "eslint.js",
"repository": {
"type": "git",
"url": "git+https://github.com/vbuch/node-signpdf.git"
},
"dependencies": {
"@eslint/js": "^9.39.5",
"@stylistic/eslint-plugin": "^5.10.0",
"eslint-plugin-import-x": "^4.18.0",
"eslint-plugin-jest": "^29.17.0",
"globals": "^17.14.0"
},
"peerDependencies": {
"eslint": "^9.39.5"
}
}
10 changes: 0 additions & 10 deletions packages/examples/.eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"js": "node src/javascript.js",
"ts": "ts-node src/typescript.ts",
"lint": "eslint -c .eslintrc --ignore-path ../../.eslintignore ./"
"lint": "eslint ."
},
"engines": {
"node": ">=22"
Expand Down
5 changes: 0 additions & 5 deletions packages/placeholder-pdf-lib/.eslintrc

This file was deleted.

10 changes: 1 addition & 9 deletions packages/placeholder-pdf-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"scripts": {
"test": "jest",
"build": "yarn build:clean && yarn build:compile && yarn build:types",
"lint": "eslint -c .eslintrc --ignore-path ../../.eslintignore ./",
"lint": "eslint .",
"build:clean": "rm -rf ./dist/*",
"build:compile": "babel ./src -d ./dist --ignore \"**/*.test.js\"",
"build:types": "yarn build:types:compile && yarn build:types:verify",
Expand All @@ -57,22 +57,14 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.4.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/node": "^7.0.0",
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.4.2",
"@signpdf/eslint-config": "^3.2.3",
"@signpdf/internal-utils": "^3.2.0",
"@types/node": ">=12.0.0",
"assertion-error": "^1.1.0",
"babel-jest": "^27.3.1",
"babel-plugin-module-resolver": "^3.1.1",
"coveralls": "^3.0.2",
"eslint": "^8.50.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.2.4",
"husky": "^7.0.4",
"jest": "^27.3.1",
"pdf-lib": "^1.17.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/placeholder-pdfkit/.eslintrc

This file was deleted.

10 changes: 1 addition & 9 deletions packages/placeholder-pdfkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"scripts": {
"test": "jest",
"build": "yarn build:clean && yarn build:compile && yarn build:types",
"lint": "eslint -c .eslintrc --ignore-path ../../.eslintignore ./",
"lint": "eslint .",
"build:clean": "rm -rf ./dist/*",
"build:compile": "babel ./src -d ./dist --ignore \"**/*.test.js\"",
"build:types": "yarn build:types:compile && yarn build:types:verify",
Expand All @@ -57,22 +57,14 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.4.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/node": "^7.0.0",
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.4.2",
"@signpdf/eslint-config": "^3.2.3",
"@signpdf/internal-utils": "^3.2.0",
"@types/node": ">=12.0.0",
"assertion-error": "^1.1.0",
"babel-jest": "^27.3.1",
"babel-plugin-module-resolver": "^3.1.1",
"coveralls": "^3.0.2",
"eslint": "^8.50.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.2.4",
"husky": "^7.0.4",
"jest": "^27.3.1",
"pdfkit": "^0.11.0",
Expand Down
21 changes: 14 additions & 7 deletions packages/placeholder-pdfkit/src/pdfkit/pdfobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default class PDFObject {
return `/${object}`;

// String objects are converted to PDF strings (UTF-16)
} if (object instanceof String) {
}
if (object instanceof String) {
let string = object;
// Detect if this is a unicode string
let isUnicode = false;
Expand Down Expand Up @@ -67,11 +68,14 @@ export default class PDFObject {
return `(${string})`;

// Buffers are converted to PDF hex strings
} if (Buffer.isBuffer(object)) {
}
if (Buffer.isBuffer(object)) {
return `<${object.toString('hex')}>`;
} if (object instanceof PDFAbstractReference) {
}
if (object instanceof PDFAbstractReference) {
return object.toString();
} if (object instanceof Date) {
}
if (object instanceof Date) {
let string = `D:${pad(object.getUTCFullYear(), 4)}${pad(object.getUTCMonth() + 1, 2)}${pad(object.getUTCDate(), 2)}${pad(object.getUTCHours(), 2)}${pad(object.getUTCMinutes(), 2)}${pad(object.getUTCSeconds(), 2)}Z`;

// Encrypt the string when necessary
Expand All @@ -83,10 +87,12 @@ export default class PDFObject {
}

return `(${string})`;
} if (Array.isArray(object)) {
}
if (Array.isArray(object)) {
const items = object.map((e) => PDFObject.convert(e, encryptFn)).join(' ');
return `[${items}]`;
} if ({}.toString.call(object) === '[object Object]') {
}
if ({}.toString.call(object) === '[object Object]') {
const out = ['<<'];
let streamData;

Expand All @@ -112,7 +118,8 @@ export default class PDFObject {
out.push(streamData);
}
return out.join('\n');
} if (typeof object === 'number') {
}
if (typeof object === 'number') {
return PDFObject.number(object);
}
return `${object}`;
Expand Down
12 changes: 5 additions & 7 deletions packages/placeholder-pdfkit/src/pdfkitAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const pdfkitAddPlaceholder = ({
widgetRect = [0, 0, 0, 0],
appName = undefined,
}) => {
/* eslint-disable no-underscore-dangle,no-param-reassign */
// Generate the signature placeholder
const signature = pdf.ref({
Type: 'Sig',
Expand All @@ -61,11 +60,11 @@ export const pdfkitAddPlaceholder = ({
byteRangePlaceholder,
],
Contents: Buffer.from(String.fromCharCode(0).repeat(signatureLength)),
Reason: new String(reason), // eslint-disable-line no-new-wrappers
Reason: new String(reason),
M: signingTime ?? new Date(),
ContactInfo: new String(contactInfo), // eslint-disable-line no-new-wrappers
Name: new String(name), // eslint-disable-line no-new-wrappers
Location: new String(location), // eslint-disable-line no-new-wrappers
ContactInfo: new String(contactInfo),
Name: new String(name),
Location: new String(location),
Prop_Build: {
Filter: {Name: 'Adobe.PPKLite'},
...(
Expand Down Expand Up @@ -95,7 +94,7 @@ export const pdfkitAddPlaceholder = ({
FT: 'Sig',
Rect: widgetRect,
V: signature,
T: new String(signatureName), // eslint-disable-line no-new-wrappers
T: new String(signatureName),
P: pdf.page.dictionary,
});

Expand All @@ -109,5 +108,4 @@ export const pdfkitAddPlaceholder = ({
form,
widget,
};
/* eslint-enable no-underscore-dangle,no-param-reassign */
};
5 changes: 0 additions & 5 deletions packages/placeholder-pdfkit010/.eslintrc

This file was deleted.

Loading
Loading