You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
Linter update (#1777)
* Update eslint config * Applied linter to lib * Applied eslint config to CliClient/app * Removed prettier due to https://github.com/prettier/prettier/pull/4765 * First pass on test units * Applied linter config to test units * Applied eslint config to clipper * Applied to plugin dir * Applied to root of ElectronClient * Applied on RN root * Applied on CLI root * Applied on Clipper root * Applied config to tools * test hook * test hook * test hook * Added pre-commit hook * Applied rule no-trailing-spaces * Make sure root packages are installed when installing sub-dir * Added doc
This commit is contained in:
@@ -2,7 +2,6 @@ const BaseItem = require('lib/models/BaseItem');
|
||||
const MasterKey = require('lib/models/MasterKey');
|
||||
const Resource = require('lib/models/Resource');
|
||||
const ResourceService = require('lib/services/ResourceService');
|
||||
const KvStore = require('lib/services/KvStore');
|
||||
const { Logger } = require('lib/logger.js');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
|
||||
@@ -194,21 +194,21 @@ class EncryptionService {
|
||||
return sjcl.codec.hex.fromBits(bitArray);
|
||||
}
|
||||
|
||||
async seedSjcl() {
|
||||
throw new Error('NOT TESTED');
|
||||
// async seedSjcl() {
|
||||
// throw new Error('NOT TESTED');
|
||||
|
||||
// Just putting this here in case it becomes needed
|
||||
// Normally seeding random bytes is not needed for our use since
|
||||
// we use shim.randomBytes directly to generate master keys.
|
||||
// // Just putting this here in case it becomes needed
|
||||
// // Normally seeding random bytes is not needed for our use since
|
||||
// // we use shim.randomBytes directly to generate master keys.
|
||||
|
||||
const sjcl = shim.sjclModule;
|
||||
const randomBytes = await shim.randomBytes(1024 / 8);
|
||||
const hexBytes = randomBytes.map(a => {
|
||||
return a.toString(16);
|
||||
});
|
||||
const hexSeed = sjcl.codec.hex.toBits(hexBytes.join(''));
|
||||
sjcl.random.addEntropy(hexSeed, 1024, 'shim.randomBytes');
|
||||
}
|
||||
// const sjcl = shim.sjclModule;
|
||||
// const randomBytes = await shim.randomBytes(1024 / 8);
|
||||
// const hexBytes = randomBytes.map(a => {
|
||||
// return a.toString(16);
|
||||
// });
|
||||
// const hexSeed = sjcl.codec.hex.toBits(hexBytes.join(''));
|
||||
// sjcl.random.addEntropy(hexSeed, 1024, 'shim.randomBytes');
|
||||
// }
|
||||
|
||||
async randomHexString(byteCount) {
|
||||
const bytes = await shim.randomBytes(byteCount);
|
||||
@@ -458,7 +458,9 @@ class EncryptionService {
|
||||
const cleanUp = async () => {
|
||||
if (source) await source.close();
|
||||
if (destination) await destination.close();
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
source = null;
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
destination = null;
|
||||
};
|
||||
|
||||
@@ -481,7 +483,9 @@ class EncryptionService {
|
||||
const cleanUp = async () => {
|
||||
if (source) await source.close();
|
||||
if (destination) await destination.close();
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
source = null;
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
destination = null;
|
||||
};
|
||||
|
||||
@@ -526,14 +530,17 @@ class EncryptionService {
|
||||
if (identifier !== 'JED') throw new Error('Invalid header (missing identifier): ' + headerHexaBytes.substr(0, 64));
|
||||
const template = this.headerTemplate(version);
|
||||
|
||||
const size = parseInt(reader.read(6), 16);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const size = parseInt(reader.read(6), 16); // Read the size and move the reader pointer forward
|
||||
|
||||
let output = {};
|
||||
|
||||
for (let i = 0; i < template.fields.length; i++) {
|
||||
const m = template.fields[i];
|
||||
const name = m[0];
|
||||
const size = m[1];
|
||||
const type = m[2];
|
||||
let v = reader.read(m[1]);
|
||||
let v = reader.read(size);
|
||||
|
||||
if (type === 'int') {
|
||||
v = parseInt(v, 16);
|
||||
@@ -543,7 +550,7 @@ class EncryptionService {
|
||||
throw new Error('Invalid type: ' + type);
|
||||
}
|
||||
|
||||
output[m[0]] = v;
|
||||
output[name] = v;
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
@@ -7,6 +7,7 @@ const { splitCommandString } = require('lib/string-utils');
|
||||
const { fileExtension, basename } = require('lib/path-utils');
|
||||
const spawn = require('child_process').spawn;
|
||||
const chokidar = require('chokidar');
|
||||
const { bridge } = require('electron').remote.require('./bridge');
|
||||
|
||||
class ExternalEditWatcher {
|
||||
constructor() {
|
||||
@@ -81,8 +82,7 @@ class ExternalEditWatcher {
|
||||
|
||||
this.skipNextChangeEvent_ = {};
|
||||
} else if (event === 'error') {
|
||||
this.logger().error('ExternalEditWatcher:');
|
||||
this.logger().error(error);
|
||||
this.logger().error('ExternalEditWatcher: error');
|
||||
}
|
||||
});
|
||||
// Hack to support external watcher on some linux applications (gedit, gvim, etc)
|
||||
@@ -100,12 +100,6 @@ class ExternalEditWatcher {
|
||||
return this.watcher_;
|
||||
}
|
||||
|
||||
static instance() {
|
||||
if (this.instance_) return this.instance_;
|
||||
this.instance_ = new ExternalEditWatcher();
|
||||
return this.instance_;
|
||||
}
|
||||
|
||||
noteIdToFilePath_(noteId) {
|
||||
return this.tempDir() + '/edit-' + noteId + '.md';
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ const Resource = require('lib/models/Resource.js');
|
||||
const Folder = require('lib/models/Folder.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const fs = require('fs-extra');
|
||||
const ArrayUtils = require('lib/ArrayUtils');
|
||||
const { sprintf } = require('sprintf-js');
|
||||
const { shim } = require('lib/shim');
|
||||
@@ -162,12 +160,14 @@ class InteropService {
|
||||
if (options.format === 'auto') {
|
||||
const module = this.moduleByFileExtension_('importer', fileExtension(options.path));
|
||||
if (!module) throw new Error(_('Please specify import format for %s', options.path));
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
options.format = module.format;
|
||||
}
|
||||
|
||||
if (options.destinationFolderId) {
|
||||
const folder = await Folder.load(options.destinationFolderId);
|
||||
if (!folder) throw new Error(_('Cannot find "%s".', options.destinationFolderId));
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
options.destinationFolder = folder;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
const InteropService_Exporter_Base = require('lib/services/InteropService_Exporter_Base');
|
||||
const InteropService_Exporter_Raw = require('lib/services/InteropService_Exporter_Raw');
|
||||
const BaseItem = require('lib/models/BaseItem.js');
|
||||
const BaseModel = require('lib/BaseModel.js');
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const Folder = require('lib/models/Folder.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const fs = require('fs-extra');
|
||||
const md5 = require('md5');
|
||||
const { shim } = require('lib/shim');
|
||||
const { _ } = require('lib/locale');
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ class InteropService_Exporter_Md extends InteropService_Exporter_Base {
|
||||
if (!item.parent_id) return output;
|
||||
item = await Folder.load(item.parent_id);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
async replaceResourceIdsByRelativePaths_(item) {
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
const InteropService_Importer_Base = require('lib/services/InteropService_Importer_Base');
|
||||
const BaseItem = require('lib/models/BaseItem.js');
|
||||
const BaseModel = require('lib/BaseModel.js');
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const Folder = require('lib/models/Folder.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const { filename } = require('lib/path-utils.js');
|
||||
const fs = require('fs-extra');
|
||||
const md5 = require('md5');
|
||||
|
||||
class InteropService_Importer_Enex extends InteropService_Importer_Base {
|
||||
async exec(result) {
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
const InteropService_Importer_Base = require('lib/services/InteropService_Importer_Base');
|
||||
const InteropService_Importer_Raw = require('lib/services/InteropService_Importer_Raw');
|
||||
const BaseItem = require('lib/models/BaseItem.js');
|
||||
const BaseModel = require('lib/BaseModel.js');
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const Folder = require('lib/models/Folder.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const { filename } = require('lib/path-utils.js');
|
||||
const fs = require('fs-extra');
|
||||
const md5 = require('md5');
|
||||
|
||||
class InteropService_Importer_Jex extends InteropService_Importer_Base {
|
||||
async exec(result) {
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
const InteropService_Importer_Base = require('lib/services/InteropService_Importer_Base');
|
||||
const BaseItem = require('lib/models/BaseItem.js');
|
||||
const BaseModel = require('lib/BaseModel.js');
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const Folder = require('lib/models/Folder.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const { basename, filename, rtrimSlashes } = require('lib/path-utils.js');
|
||||
const fs = require('fs-extra');
|
||||
const md5 = require('md5');
|
||||
const { shim } = require('lib/shim');
|
||||
const { _ } = require('lib/locale');
|
||||
const { fileExtension } = require('lib/path-utils');
|
||||
|
||||
@@ -6,8 +6,6 @@ const Folder = require('lib/models/Folder.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const fs = require('fs-extra');
|
||||
const md5 = require('md5');
|
||||
const { sprintf } = require('sprintf-js');
|
||||
const { shim } = require('lib/shim');
|
||||
const { fileExtension } = require('lib/path-utils');
|
||||
@@ -49,6 +47,7 @@ class InteropService_Importer_Raw extends InteropService_Importer_Base {
|
||||
const defaultFolder = async () => {
|
||||
if (defaultFolder_) return defaultFolder_;
|
||||
const folderTitle = await Folder.findUniqueItemTitle(this.options_.defaultFolderTitle ? this.options_.defaultFolderTitle : 'Imported');
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
defaultFolder_ = await Folder.save({ title: folderTitle });
|
||||
return defaultFolder_;
|
||||
};
|
||||
@@ -65,6 +64,7 @@ class InteropService_Importer_Raw extends InteropService_Importer_Base {
|
||||
itemIdMap[itemParentId] = destinationFolderId;
|
||||
} else if (!itemParentExists) {
|
||||
const parentFolder = await defaultFolder();
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
itemIdMap[itemParentId] = parentFolder.id;
|
||||
} else {
|
||||
itemIdMap[itemParentId] = uuid.create();
|
||||
|
||||
@@ -8,7 +8,6 @@ const ItemChangeUtils = require('lib/services/ItemChangeUtils');
|
||||
const { shim } = require('lib/shim');
|
||||
const BaseService = require('lib/services/BaseService');
|
||||
const { _ } = require('lib/locale.js');
|
||||
const ArrayUtils = require('lib/ArrayUtils.js');
|
||||
const { sprintf } = require('sprintf-js');
|
||||
|
||||
class RevisionService extends BaseService {
|
||||
|
||||
@@ -134,8 +134,6 @@ class SearchEngine {
|
||||
[BaseModel.TYPE_NOTE, lastChangeId]
|
||||
);
|
||||
|
||||
const maxRow = await ItemChange.db().selectOne('SELECT max(id) FROM item_changes');
|
||||
|
||||
if (!changes.length) break;
|
||||
|
||||
const noteIds = changes.map(a => a.item_id);
|
||||
|
||||
@@ -4,9 +4,9 @@ const Folder = require('lib/models/Folder');
|
||||
const Note = require('lib/models/Note');
|
||||
const Tag = require('lib/models/Tag');
|
||||
const BaseItem = require('lib/models/BaseItem');
|
||||
const Resource = require('lib/models/Resource');
|
||||
const BaseModel = require('lib/BaseModel');
|
||||
const Setting = require('lib/models/Setting');
|
||||
const markdownUtils = require('lib/markdownUtils');
|
||||
const htmlUtils = require('lib/htmlUtils');
|
||||
const markupLanguageUtils = require('lib/markupLanguageUtils');
|
||||
const mimeUtils = require('lib/mime-utils.js').mime;
|
||||
@@ -591,12 +591,9 @@ class Api {
|
||||
|
||||
const output = {};
|
||||
|
||||
const downloadOne = url => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const imagePath = await this.downloadImage_(url, allowFileProtocolImages);
|
||||
if (imagePath) output[url] = { path: imagePath, originalUrl: url };
|
||||
resolve();
|
||||
});
|
||||
const downloadOne = async url => {
|
||||
const imagePath = await this.downloadImage_(url, allowFileProtocolImages);
|
||||
if (imagePath) output[url] = { path: imagePath, originalUrl: url };
|
||||
};
|
||||
|
||||
let urlIndex = 0;
|
||||
@@ -650,7 +647,8 @@ class Api {
|
||||
return Resource.internalUrl(urlInfo.resource);
|
||||
});
|
||||
} else {
|
||||
let output = md.replace(/(!\[.*?\]\()([^\s\)]+)(.*?\))/g, (match, before, imageUrl, after) => {
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
return md.replace(/(!\[.*?\]\()([^\s\)]+)(.*?\))/g, (match, before, imageUrl, after) => {
|
||||
const urlInfo = urls[imageUrl];
|
||||
if (!urlInfo || !urlInfo.resource) return before + imageUrl + after;
|
||||
if (!(urlInfo.originalUrl in imageSizesIndexes)) imageSizesIndexes[urlInfo.originalUrl] = 0;
|
||||
@@ -664,8 +662,6 @@ class Api {
|
||||
return before + resourceUrl + after;
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user