Skip to content

Commit

Permalink
fix: eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jul 2, 2022
1 parent 17b4445 commit 29a6e11
Show file tree
Hide file tree
Showing 9 changed files with 733 additions and 1,217 deletions.
2 changes: 1 addition & 1 deletion dist/virtualfs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/virtualfs.js.map

Large diffs are not rendered by default.

1,818 changes: 662 additions & 1,156 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"devDependencies": {
"browser-mime": "1.0.1",
"eslint": "5.16.0",
"eslint": "8.19.0",
"filer": "1.4.1",
"http-server": "14.1.0",
"idb": "7.0.1",
Expand Down
20 changes: 10 additions & 10 deletions src/filerlib_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
const {ERR_CODES, Errors} = require('./errno');
const ERROR_CODES = ERR_CODES.ERROR_CODES;

async function _stat(path) {
return new Promise(async (resolve, reject) => {
function _stat(path) {
return new Promise((resolve, reject) => {
fs.stat(path, async (err, stat) => {
if(err && err.code === ERROR_CODES.ENOENT){
resolve(null);
Expand All @@ -39,8 +39,8 @@ async function _stat(path) {
});
}

async function _mkdirIfNotPresent(path) {
return new Promise(async (resolve, reject) => {
function _mkdirIfNotPresent(path) {
return new Promise((resolve, reject) => {
fs.mkdir(path, async (err) => {
err && err.code !== ERROR_CODES.EEXIST?
reject(err):
Expand All @@ -49,9 +49,9 @@ async function _mkdirIfNotPresent(path) {
});
}

async function _readDir(path) {
return new Promise(async (resolve, reject) => {
fs.readdir(path, async (err, listing) => {
function _readDir(path) {
return new Promise((resolve, reject) => {
fs.readdir(path, (err, listing) => {
if(err) {
reject(err);
} else {
Expand All @@ -61,9 +61,9 @@ async function _readDir(path) {
});
}

async function _copyFileContents(src, dst) {
return new Promise(async (resolve, reject) => {
fs.readFile(src, async (err, data) => {
function _copyFileContents(src, dst) {
return new Promise((resolve, reject) => {
fs.readFile(src, (err, data) => {
if(err) {
reject(err);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/fslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

// jshint ignore: start
/*global process, globalObject*/
/*global globalObject*/
/*eslint no-console: 0*/
/*eslint strict: ["error", "global"]*/

Expand Down
27 changes: 16 additions & 11 deletions src/fslib_mounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

// jshint ignore: start
/*global BroadcastChannel, globalObject*/
/*global globalObject*/
/*eslint no-console: 0*/
/*eslint strict: ["error", "global"]*/

Expand Down Expand Up @@ -162,18 +162,23 @@ function _getNewMountName(handleToMount) {
* @private
*/
function _mountHandle(handleToMount) {
return new Promise(async (resolve, reject) => {
let path = await _getPathIfAlreadyMounted(handleToMount);
if(path){
resolve(path);
} else {
let mountName = _getNewMountName(handleToMount);
if(!mountName) {
reject('Mount name not fount');
return new Promise(async (resolve, reject) => { // eslint-disable-line
// eslint async executors are needed here. we explicitly catch so it's fine.
try{
let path = await _getPathIfAlreadyMounted(handleToMount);
if(path){
resolve(path);
} else {
await MountPointsStore.addMountPoint(mountName, handleToMount);
resolve(`${Constants.MOUNT_POINT_ROOT}/${mountName}`);
let mountName = _getNewMountName(handleToMount);
if(!mountName) {
reject('Mount name not fount');
} else {
await MountPointsStore.addMountPoint(mountName, handleToMount);
resolve(`${Constants.MOUNT_POINT_ROOT}/${mountName}`);
}
}
} catch (e) {
reject(e);
}
});
}
Expand Down
75 changes: 40 additions & 35 deletions src/fslib_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

// jshint ignore: start
/*global TextDecoder, buffer, globalObject*/
/*global buffer, globalObject*/
/*eslint no-console: 0*/
/*eslint strict: ["error", "global"]*/

Expand Down Expand Up @@ -261,41 +261,46 @@ async function unlink(path, callback) {
}

async function _getDestinationHandleForCopy(dst, srcBaseName, handleKindToCreate) {
return new Promise(async (resolve, reject) => {
dst = globalObject.path.normalize(dst);
let dirPath= globalObject.path.dirname(dst);
let dstBaseName= globalObject.path.basename(dst);
let dstHandle = await Mounts.getHandleFromPathIfPresent(dst);
let dstParentHandle = await Mounts.getHandleFromPathIfPresent(dirPath);
if (dstHandle && dstHandle.kind === Constants.KIND_FILE) {
reject(new Errors.EEXIST(`Destination file already exists: ${dst}`));
} else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_FILE) {
const fileHandle = await dstHandle.getFileHandle(srcBaseName, {create: true});
const dstPath = `${dst}/${srcBaseName}`;
resolve({handle: fileHandle, path:dstPath});
} else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_DIRECTORY) {
let dstChildHandle = await Mounts.getHandleFromPathIfPresent(`${dst}/${srcBaseName}`);
if(dstChildHandle){
reject(new Errors.EEXIST(`Copy destination already exists: ${dst}/${srcBaseName}`));
return;
return new Promise(async (resolve, reject) => { // eslint-disable-line
// eslint async executors are needed here. we explicitly catch so it's fine.
try{
dst = globalObject.path.normalize(dst);
let dirPath= globalObject.path.dirname(dst);
let dstBaseName= globalObject.path.basename(dst);
let dstHandle = await Mounts.getHandleFromPathIfPresent(dst);
let dstParentHandle = await Mounts.getHandleFromPathIfPresent(dirPath);
if (dstHandle && dstHandle.kind === Constants.KIND_FILE) {
reject(new Errors.EEXIST(`Destination file already exists: ${dst}`));
} else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_FILE) {
const fileHandle = await dstHandle.getFileHandle(srcBaseName, {create: true});
const dstPath = `${dst}/${srcBaseName}`;
resolve({handle: fileHandle, path:dstPath});
} else if (dstHandle && dstHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_DIRECTORY) {
let dstChildHandle = await Mounts.getHandleFromPathIfPresent(`${dst}/${srcBaseName}`);
if(dstChildHandle){
reject(new Errors.EEXIST(`Copy destination already exists: ${dst}/${srcBaseName}`));
return;
}
const directoryHandle = await dstHandle.getDirectoryHandle(srcBaseName, {create: true});
const dstPath = `${dst}/${srcBaseName}`;
resolve({handle: directoryHandle, path: dstPath});
} else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_FILE) {
const fileHandle = await dstParentHandle.getFileHandle(dstBaseName, {create: true});
const dstPath = `${dirPath}/${dstBaseName}`;
resolve({handle: fileHandle, path: dstPath});
} else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_DIRECTORY) {
const fileHandle = await dstParentHandle.getDirectoryHandle(dstBaseName, {create: true});
const dstPath = `${dirPath}/${dstBaseName}`;
resolve({handle: fileHandle, path: dstPath});
} else {
reject(new Errors.ENOENT(`Copy destination doesnt exist: ${dst}`));
}
const directoryHandle = await dstHandle.getDirectoryHandle(srcBaseName, {create: true});
const dstPath = `${dst}/${srcBaseName}`;
resolve({handle: directoryHandle, path: dstPath});
} else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_FILE) {
const fileHandle = await dstParentHandle.getFileHandle(dstBaseName, {create: true});
const dstPath = `${dirPath}/${dstBaseName}`;
resolve({handle: fileHandle, path: dstPath});
} else if (!dstHandle && dstParentHandle && dstParentHandle.kind === Constants.KIND_DIRECTORY
&& handleKindToCreate === Constants.KIND_DIRECTORY) {
const fileHandle = await dstParentHandle.getDirectoryHandle(dstBaseName, {create: true});
const dstPath = `${dirPath}/${dstBaseName}`;
resolve({handle: fileHandle, path: dstPath});
} else {
reject(new Errors.ENOENT(`Copy destination doesnt exist: ${dst}`));
} catch (e) {
reject(e);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/fslib_watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

// jshint ignore: start
/*global BroadcastChannel, globalObject, virtualfs*/
/*global globalObject, virtualfs*/
/*eslint no-console: 0*/
/*eslint strict: ["error", "global"]*/

Expand Down

0 comments on commit 29a6e11

Please sign in to comment.