Skip to content

Commit ab22fe8

Browse files
authored
Lint: enforce single quotes and do not error on class methods without this (#1341)
1 parent d238a02 commit ab22fe8

43 files changed

Lines changed: 333 additions & 344 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
}
7373
],
7474
"capitalized-comments": "off",
75-
"class-methods-use-this": "error",
75+
"class-methods-use-this": "off",
7676
"comma-dangle": [ "error", "never" ],
7777
"comma-spacing": "off",
7878
"comma-style": [
@@ -278,7 +278,7 @@ module.exports = {
278278
"prefer-spread": "off",
279279
"prefer-template": "off",
280280
"quote-props": "off",
281-
"quotes": "off",
281+
"quotes": ["error", "single", { "avoidEscape": true }],
282282
"require-await": "error",
283283
"require-jsdoc": "off",
284284
"semi-spacing": [

rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { builtinModules } from 'module';
55
import resolve from '@rollup/plugin-node-resolve';
66
import commonjs from '@rollup/plugin-commonjs';
77
import replace from '@rollup/plugin-replace';
8-
import { terser } from "rollup-plugin-terser";
8+
import { terser } from 'rollup-plugin-terser';
99

1010
import pkg from './package.json';
1111

@@ -16,7 +16,7 @@ const banner =
1616
`${new Date().toISOString().split('T')[0]} - ` +
1717
`this is LGPL licensed code, see LICENSE/our website ${pkg.homepage} for more information. */`;
1818

19-
const intro = `const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};`;
19+
const intro = "const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};";
2020

2121
const terserOptions = {
2222
ecma: 2017,

src/biginteger/native.interface.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ export default class BigInteger {
155155
* @returns {BigInteger} this ** e mod n.
156156
*/
157157
modExp(e, n) {
158-
if (n.isZero()) throw Error("Modulo cannot be zero");
158+
if (n.isZero()) throw Error('Modulo cannot be zero');
159159
if (n.isOne()) return new BigInteger(0);
160-
if (e.isNegative()) throw Error("Unsopported negative exponent");
160+
if (e.isNegative()) throw Error('Unsopported negative exponent');
161161

162162
let exp = e.value;
163163
let x = this.value;

src/config/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ export default {
154154
* @memberof module:config
155155
* @property {String} versionString A version string to be included in armored messages
156156
*/
157-
versionString: "OpenPGP.js VERSION",
157+
versionString: 'OpenPGP.js VERSION',
158158
/**
159159
* @memberof module:config
160160
* @property {String} commentString A comment string to be included in armored messages
161161
*/
162-
commentString: "https://openpgpjs.org",
162+
commentString: 'https://openpgpjs.org',
163163

164164
/**
165165
* Max userID string length (used for parsing)
@@ -173,7 +173,7 @@ export default {
173173
* @memberof module:config
174174
* @property {Array} knownNotations
175175
*/
176-
knownNotations: ["preferred-email-encoding@pgp.com", "pka-address@gnupg.org"],
176+
knownNotations: ['preferred-email-encoding@pgp.com', 'pka-address@gnupg.org'],
177177
/**
178178
* @memberof module:config
179179
* @property {Boolean} useIndutnyElliptic Whether to use the indutny/elliptic library. When false, certain curves will not be supported.

src/crypto/aes_kw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import util from '../util';
3333
* @returns {Uint8Array}
3434
*/
3535
export function wrap(key, data) {
36-
const aes = new cipher["aes" + (key.length * 8)](key);
36+
const aes = new cipher['aes' + (key.length * 8)](key);
3737
const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
3838
const P = unpack(data);
3939
let A = IV;
@@ -73,7 +73,7 @@ export function wrap(key, data) {
7373
* @throws {Error}
7474
*/
7575
export function unwrap(key, data) {
76-
const aes = new cipher["aes" + (key.length * 8)](key);
76+
const aes = new cipher['aes' + (key.length * 8)](key);
7777
const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
7878
const C = unpack(data);
7979
let A = C.subarray(0, 2);
@@ -102,7 +102,7 @@ export function unwrap(key, data) {
102102
if (A[0] === IV[0] && A[1] === IV[1]) {
103103
return pack(R);
104104
}
105-
throw new Error("Key Data Integrity failed");
105+
throw new Error('Key Data Integrity failed');
106106
}
107107

108108
function createArrayBuffer(data) {

src/crypto/cipher/des.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function desAddPadding(message, padding) {
384384

385385
let pad;
386386
if (padding === 2 && (padLength < 8)) { //pad the message with spaces
387-
pad = " ".charCodeAt(0);
387+
pad = ' '.charCodeAt(0);
388388
} else if (padding === 1) { //PKCS7 padding
389389
pad = padLength;
390390
} else if (!padding && (padLength < 8)) { //pad the message out with null bytes
@@ -410,7 +410,7 @@ function desRemovePadding(message, padding) {
410410
let padLength = null;
411411
let pad;
412412
if (padding === 2) { // space padded
413-
pad = " ".charCodeAt(0);
413+
pad = ' '.charCodeAt(0);
414414
} else if (padding === 1) { // PKCS7
415415
padLength = message[message.length - 1];
416416
} else if (!padding) { // null padding

src/crypto/cipher/twofish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function createTwofish() {
318318
}
319319

320320
return {
321-
name: "twofish",
321+
name: 'twofish',
322322
blocksize: 128 / 8,
323323
open: tfsInit,
324324
close: tfsClose,

src/crypto/public_key/dsa.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ export async function verify(hashAlgo, r, s, hashed, g, p, q, y) {
113113

114114
if (r.lte(zero) || r.gte(q) ||
115115
s.lte(zero) || s.gte(q)) {
116-
util.printDebug("invalid DSA Signature");
116+
util.printDebug('invalid DSA Signature');
117117
return false;
118118
}
119119
const h = new BigInteger(hashed.subarray(0, q.byteLength())).imod(q);
120120
const w = s.modInv(q); // s**-1 mod q
121121
if (w.isZero()) {
122-
util.printDebug("invalid DSA Signature");
122+
util.printDebug('invalid DSA Signature');
123123
return false;
124124
}
125125

src/crypto/public_key/elliptic/curves.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class Curve {
175175
try {
176176
return await webGenKeyPair(this.name);
177177
} catch (err) {
178-
util.printDebugError("Browser did not support generating ec key " + err.message);
178+
util.printDebugError('Browser did not support generating ec key ' + err.message);
179179
break;
180180
}
181181
case 'node':
@@ -299,10 +299,10 @@ export {
299299

300300
async function webGenKeyPair(name) {
301301
// Note: keys generated with ECDSA and ECDH are structurally equivalent
302-
const webCryptoKey = await webCrypto.generateKey({ name: "ECDSA", namedCurve: webCurves[name] }, true, ["sign", "verify"]);
302+
const webCryptoKey = await webCrypto.generateKey({ name: 'ECDSA', namedCurve: webCurves[name] }, true, ['sign', 'verify']);
303303

304-
const privateKey = await webCrypto.exportKey("jwk", webCryptoKey.privateKey);
305-
const publicKey = await webCrypto.exportKey("jwk", webCryptoKey.publicKey);
304+
const privateKey = await webCrypto.exportKey('jwk', webCryptoKey.privateKey);
305+
const publicKey = await webCrypto.exportKey('jwk', webCryptoKey.publicKey);
306306

307307
return {
308308
publicKey: jwkToRawPublic(publicKey),
@@ -354,7 +354,7 @@ function rawPublicToJWK(payloadSize, name, publicKey) {
354354
const bufY = publicKey.slice(len + 1, len * 2 + 1);
355355
// https://www.rfc-editor.org/rfc/rfc7518.txt
356356
const jwk = {
357-
kty: "EC",
357+
kty: 'EC',
358358
crv: name,
359359
x: uint8ArrayToB64(bufX, true),
360360
y: uint8ArrayToB64(bufY, true),

src/crypto/public_key/elliptic/ecdh.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function buildEcdhParam(public_algo, oid, kdfParams, fingerprint) {
5454
oid.write(),
5555
new Uint8Array([public_algo]),
5656
kdfParams.write(),
57-
util.stringToUint8Array("Anonymous Sender "),
57+
util.stringToUint8Array('Anonymous Sender '),
5858
fingerprint.subarray(0, 20)
5959
]);
6060
}
@@ -219,21 +219,21 @@ export async function decrypt(oid, kdfParams, V, C, Q, d, fingerprint) {
219219
async function webPrivateEphemeralKey(curve, V, Q, d) {
220220
const recipient = privateToJWK(curve.payloadSize, curve.web.web, Q, d);
221221
let privateKey = webCrypto.importKey(
222-
"jwk",
222+
'jwk',
223223
recipient,
224224
{
225-
name: "ECDH",
225+
name: 'ECDH',
226226
namedCurve: curve.web.web
227227
},
228228
true,
229-
["deriveKey", "deriveBits"]
229+
['deriveKey', 'deriveBits']
230230
);
231231
const jwk = rawPublicToJWK(curve.payloadSize, curve.web.web, V);
232232
let sender = webCrypto.importKey(
233-
"jwk",
233+
'jwk',
234234
jwk,
235235
{
236-
name: "ECDH",
236+
name: 'ECDH',
237237
namedCurve: curve.web.web
238238
},
239239
true,
@@ -242,15 +242,15 @@ async function webPrivateEphemeralKey(curve, V, Q, d) {
242242
[privateKey, sender] = await Promise.all([privateKey, sender]);
243243
let S = webCrypto.deriveBits(
244244
{
245-
name: "ECDH",
245+
name: 'ECDH',
246246
namedCurve: curve.web.web,
247247
public: sender
248248
},
249249
privateKey,
250250
curve.web.sharedSize
251251
);
252252
let secret = webCrypto.exportKey(
253-
"jwk",
253+
'jwk',
254254
privateKey
255255
);
256256
[S, secret] = await Promise.all([S, secret]);
@@ -271,17 +271,17 @@ async function webPublicEphemeralKey(curve, Q) {
271271
const jwk = rawPublicToJWK(curve.payloadSize, curve.web.web, Q);
272272
let keyPair = webCrypto.generateKey(
273273
{
274-
name: "ECDH",
274+
name: 'ECDH',
275275
namedCurve: curve.web.web
276276
},
277277
true,
278-
["deriveKey", "deriveBits"]
278+
['deriveKey', 'deriveBits']
279279
);
280280
let recipient = webCrypto.importKey(
281-
"jwk",
281+
'jwk',
282282
jwk,
283283
{
284-
name: "ECDH",
284+
name: 'ECDH',
285285
namedCurve: curve.web.web
286286
},
287287
false,
@@ -290,15 +290,15 @@ async function webPublicEphemeralKey(curve, Q) {
290290
[keyPair, recipient] = await Promise.all([keyPair, recipient]);
291291
let s = webCrypto.deriveBits(
292292
{
293-
name: "ECDH",
293+
name: 'ECDH',
294294
namedCurve: curve.web.web,
295295
public: recipient
296296
},
297297
keyPair.privateKey,
298298
curve.web.sharedSize
299299
);
300300
let p = webCrypto.exportKey(
301-
"jwk",
301+
'jwk',
302302
keyPair.publicKey
303303
);
304304
[s, p] = await Promise.all([s, p]);

0 commit comments

Comments
 (0)