Commit e7d50054 authored by Lukas Eipert's avatar Lukas Eipert

Run prettier on 31 files - 16 of 73

Part of our prettier migration; changing the arrow-parens style.
parent 00827a74
......@@ -8,7 +8,7 @@ const plugins = () => [
export default (store, el) => {
// plugins is actually an array of plugin factories, so we have to create first then call
plugins().forEach(plugin => plugin(el)(store));
plugins().forEach((plugin) => plugin(el)(store));
return store;
};
......@@ -9,19 +9,19 @@ import {
import { addNumericSuffix } from '~/ide/utils';
import Api from '~/api';
export const activeFile = state => state.openFiles.find(file => file.active) || null;
export const activeFile = (state) => state.openFiles.find((file) => file.active) || null;
export const addedFiles = state => state.changedFiles.filter(f => f.tempFile);
export const addedFiles = (state) => state.changedFiles.filter((f) => f.tempFile);
export const modifiedFiles = state => state.changedFiles.filter(f => !f.tempFile);
export const modifiedFiles = (state) => state.changedFiles.filter((f) => !f.tempFile);
export const projectsWithTrees = state =>
Object.keys(state.projects).map(projectId => {
export const projectsWithTrees = (state) =>
Object.keys(state.projects).map((projectId) => {
const project = state.projects[projectId];
return {
...project,
branches: Object.keys(project.branches).map(branchId => {
branches: Object.keys(project.branches).map((branchId) => {
const branch = project.branches[branchId];
return {
......@@ -32,7 +32,7 @@ export const projectsWithTrees = state =>
};
});
export const currentMergeRequest = state => {
export const currentMergeRequest = (state) => {
if (
state.projects[state.currentProjectId] &&
state.projects[state.currentProjectId].mergeRequests
......@@ -42,19 +42,19 @@ export const currentMergeRequest = state => {
return null;
};
export const findProject = state => projectId => state.projects[projectId];
export const findProject = (state) => (projectId) => state.projects[projectId];
export const currentProject = (state, getters) => getters.findProject(state.currentProjectId);
export const emptyRepo = state =>
export const emptyRepo = (state) =>
state.projects[state.currentProjectId] && state.projects[state.currentProjectId].empty_repo;
export const currentTree = state =>
export const currentTree = (state) =>
state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
export const hasMergeRequest = state => Boolean(state.currentMergeRequestId);
export const hasMergeRequest = (state) => Boolean(state.currentMergeRequestId);
export const allBlobs = state =>
export const allBlobs = (state) =>
Object.keys(state.entries)
.reduce((acc, key) => {
const entry = state.entries[key];
......@@ -67,35 +67,35 @@ export const allBlobs = state =>
}, [])
.sort((a, b) => b.lastOpenedAt - a.lastOpenedAt);
export const getChangedFile = state => path => state.changedFiles.find(f => f.path === path);
export const getStagedFile = state => path => state.stagedFiles.find(f => f.path === path);
export const getOpenFile = state => path => state.openFiles.find(f => f.path === path);
export const getChangedFile = (state) => (path) => state.changedFiles.find((f) => f.path === path);
export const getStagedFile = (state) => (path) => state.stagedFiles.find((f) => f.path === path);
export const getOpenFile = (state) => (path) => state.openFiles.find((f) => f.path === path);
export const lastOpenedFile = state =>
export const lastOpenedFile = (state) =>
[...state.changedFiles, ...state.stagedFiles].sort((a, b) => b.lastOpenedAt - a.lastOpenedAt)[0];
export const isEditModeActive = state => state.currentActivityView === leftSidebarViews.edit.name;
export const isCommitModeActive = state =>
export const isEditModeActive = (state) => state.currentActivityView === leftSidebarViews.edit.name;
export const isCommitModeActive = (state) =>
state.currentActivityView === leftSidebarViews.commit.name;
export const isReviewModeActive = state =>
export const isReviewModeActive = (state) =>
state.currentActivityView === leftSidebarViews.review.name;
export const someUncommittedChanges = state =>
export const someUncommittedChanges = (state) =>
Boolean(state.changedFiles.length || state.stagedFiles.length);
export const getChangesInFolder = state => path => {
const changedFilesCount = state.changedFiles.filter(f => filePathMatches(f.path, path)).length;
export const getChangesInFolder = (state) => (path) => {
const changedFilesCount = state.changedFiles.filter((f) => filePathMatches(f.path, path)).length;
const stagedFilesCount = state.stagedFiles.filter(
f => filePathMatches(f.path, path) && !getChangedFile(state)(f.path),
(f) => filePathMatches(f.path, path) && !getChangedFile(state)(f.path),
).length;
return changedFilesCount + stagedFilesCount;
};
export const getUnstagedFilesCountForPath = state => path =>
export const getUnstagedFilesCountForPath = (state) => (path) =>
getChangesCountForFiles(state.changedFiles, path);
export const getStagedFilesCountForPath = state => path =>
export const getStagedFilesCountForPath = (state) => (path) =>
getChangesCountForFiles(state.stagedFiles, path);
export const lastCommit = (state, getters) => {
......@@ -115,7 +115,7 @@ export const currentBranch = (state, getters) =>
export const branchName = (_state, getters) => getters.currentBranch && getters.currentBranch.name;
export const packageJson = state => state.entries[packageJsonPath];
export const packageJson = (state) => state.entries[packageJsonPath];
export const isOnDefaultBranch = (_state, getters) =>
getters.currentProject && getters.currentProject.default_branch === getters.branchName;
......@@ -124,14 +124,14 @@ export const canPushToBranch = (_state, getters) => {
return Boolean(getters.currentBranch ? getters.currentBranch.can_push : getters.canPushCode);
};
export const isFileDeletedAndReadded = (state, getters) => path => {
export const isFileDeletedAndReadded = (state, getters) => (path) => {
const stagedFile = getters.getStagedFile(path);
const file = state.entries[path];
return Boolean(stagedFile && stagedFile.deleted && file.tempFile);
};
// checks if any diff exists in the staged or unstaged changes for this path
export const getDiffInfo = (state, getters) => path => {
export const getDiffInfo = (state, getters) => (path) => {
const stagedFile = getters.getStagedFile(path);
const file = state.entries[path];
const renamed = file.prevPath ? file.path !== file.prevPath : false;
......@@ -149,7 +149,7 @@ export const getDiffInfo = (state, getters) => path => {
};
};
export const findProjectPermissions = (state, getters) => projectId =>
export const findProjectPermissions = (state, getters) => (projectId) =>
getters.findProject(projectId)?.userPermissions || {};
export const canReadMergeRequests = (state, getters) =>
......@@ -161,10 +161,10 @@ export const canCreateMergeRequests = (state, getters) =>
export const canPushCode = (state, getters) =>
Boolean(getters.findProjectPermissions(state.currentProjectId)[PERMISSION_PUSH_CODE]);
export const entryExists = state => path =>
export const entryExists = (state) => (path) =>
Boolean(state.entries[path] && !state.entries[path].deleted);
export const getAvailableFileName = (state, getters) => path => {
export const getAvailableFileName = (state, getters) => (path) => {
let newPath = path;
while (getters.entryExists(newPath)) {
......@@ -174,10 +174,10 @@ export const getAvailableFileName = (state, getters) => path => {
return newPath;
};
export const getUrlForPath = state => path =>
export const getUrlForPath = (state) => (path) =>
`/project/${state.currentProjectId}/tree/${state.currentBranchId}/-/${path}/`;
export const getJsonSchemaForPath = (state, getters) => path => {
export const getJsonSchemaForPath = (state, getters) => (path) => {
const [namespace, ...project] = state.currentProjectId.split('/');
return {
uri:
......
......@@ -8,7 +8,7 @@ export const receiveBranchesError = ({ commit, dispatch }, { search }) => {
'setErrorMessage',
{
text: __('Error loading branches.'),
action: payload =>
action: (payload) =>
dispatch('fetchBranches', payload).then(() =>
dispatch('setErrorMessage', null, { root: true }),
),
......
......@@ -9,7 +9,7 @@ export default {
},
[types.RECEIVE_BRANCHES_SUCCESS](state, data) {
state.isLoading = false;
state.branches = data.map(branch => ({
state.branches = data.map((branch) => ({
name: branch.name,
committedDate: branch.commit.committed_date,
}));
......
......@@ -78,8 +78,8 @@ export const updateFilesAfterCommit = ({ commit, dispatch, rootState, rootGetter
{ root: true },
);
rootState.stagedFiles.forEach(file => {
const changedFile = rootState.changedFiles.find(f => f.path === file.path);
rootState.stagedFiles.forEach((file) => {
const changedFile = rootState.changedFiles.find((f) => f.path === file.path);
commit(
rootTypes.UPDATE_FILE_AFTER_COMMIT,
......@@ -133,7 +133,7 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
return service.commit(rootState.currentProjectId, payload);
})
.catch(e => {
.catch((e) => {
commit(types.UPDATE_LOADING, false);
commit(types.SET_ERROR, parseCommitError(e));
......@@ -193,12 +193,12 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
},
{ root: true },
)
.then(changeViewer => {
.then((changeViewer) => {
if (changeViewer) {
dispatch('updateViewer', 'diff', { root: true });
}
})
.catch(e => {
.catch((e) => {
throw e;
});
} else {
......
......@@ -11,7 +11,7 @@ const createTranslatedTextForFiles = (files, text) => {
});
};
export const discardDraftButtonDisabled = state =>
export const discardDraftButtonDisabled = (state) =>
state.commitMessage === '' || state.submitCommitLoading;
// Note: If changing the structure of the placeholder branch name, please also
......@@ -37,18 +37,18 @@ export const preBuiltCommitMessage = (state, _, rootState) => {
if (state.commitMessage) return state.commitMessage;
const files = rootState.stagedFiles.length ? rootState.stagedFiles : rootState.changedFiles;
const modifiedFiles = files.filter(f => !f.deleted);
const deletedFiles = files.filter(f => f.deleted);
const modifiedFiles = files.filter((f) => !f.deleted);
const deletedFiles = files.filter((f) => f.deleted);
return [
createTranslatedTextForFiles(modifiedFiles, __('Update')),
createTranslatedTextForFiles(deletedFiles, __('Deleted')),
]
.filter(t => t)
.filter((t) => t)
.join('\n');
};
export const isCreatingNewBranch = state => state.commitAction === consts.COMMIT_TO_NEW_BRANCH;
export const isCreatingNewBranch = (state) => state.commitAction === consts.COMMIT_TO_NEW_BRANCH;
export const shouldHideNewMrOption = (_state, getters, _rootState, rootGetters) =>
!getters.isCreatingNewBranch &&
......
import eventHub from '~/ide/eventhub';
import { commitActionTypes } from '~/ide/constants';
const removeUnusedFileEditors = store => {
const removeUnusedFileEditors = (store) => {
Object.keys(store.state.editor.fileEditors)
.filter(path => !store.state.entries[path])
.forEach(path => store.dispatch('editor/removeFileEditor', path));
.filter((path) => !store.state.entries[path])
.forEach((path) => store.dispatch('editor/removeFileEditor', path));
};
export const setupFileEditorsSync = store => {
export const setupFileEditorsSync = (store) => {
eventHub.$on('ide.files.change', ({ type, ...payload } = {}) => {
if (type === commitActionTypes.move) {
store.dispatch('editor/renameFileEditor', payload);
......
......@@ -68,7 +68,7 @@ export const receiveTemplateError = ({ dispatch }, template) => {
'setErrorMessage',
{
text: __('Error loading template.'),
action: payload =>
action: (payload) =>
dispatch('fetchTemplateTypes', payload).then(() =>
dispatch('setErrorMessage', null, { root: true }),
),
......
......@@ -24,6 +24,6 @@ export const templateTypes = () => [
},
];
export const showFileTemplatesBar = (_, getters, rootState) => name =>
getters.templateTypes.find(t => t.name === name) &&
export const showFileTemplatesBar = (_, getters, rootState) => (name) =>
getters.templateTypes.find((t) => t.name === name) &&
rootState.currentActivityView === leftSidebarViews.edit.name;
......@@ -9,7 +9,7 @@ export const receiveMergeRequestsError = ({ commit, dispatch }, { type, search }
'setErrorMessage',
{
text: __('Error loading merge requests.'),
action: payload =>
action: (payload) =>
dispatch('fetchMergeRequests', payload).then(() =>
dispatch('setErrorMessage', null, { root: true }),
),
......
......@@ -9,7 +9,7 @@ export default {
},
[types.RECEIVE_MERGE_REQUESTS_SUCCESS](state, data) {
state.isLoading = false;
state.mergeRequests = data.map(mergeRequest => ({
state.mergeRequests = data.map((mergeRequest) => ({
id: mergeRequest.id,
iid: mergeRequest.iid,
title: mergeRequest.title,
......
export const isAliveView = state => view =>
export const isAliveView = (state) => (view) =>
state.keepAliveViews[view] || (state.isOpen && state.currentView === view);
......@@ -47,7 +47,7 @@ export const receiveLatestPipelineSuccess = ({ rootGetters, commit }, { pipeline
if (pipelines && pipelines.length) {
const lastCommitHash = rootGetters.lastCommit && rootGetters.lastCommit.id;
lastCommitPipeline = pipelines.find(pipeline => pipeline.commit.id === lastCommitHash);
lastCommitPipeline = pipelines.find((pipeline) => pipeline.commit.id === lastCommitHash);
}
commit(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, lastCommitPipeline);
......@@ -63,7 +63,7 @@ export const fetchLatestPipeline = ({ dispatch, rootGetters }) => {
method: 'lastCommitPipelines',
data: { getters: rootGetters },
successCallback: ({ data }) => dispatch('receiveLatestPipelineSuccess', data),
errorCallback: err => dispatch('receiveLatestPipelineError', err),
errorCallback: (err) => dispatch('receiveLatestPipelineError', err),
});
if (!Visibility.hidden()) {
......@@ -85,7 +85,7 @@ export const receiveJobsError = ({ commit, dispatch }, stage) => {
'setErrorMessage',
{
text: __('An error occurred while loading the pipelines jobs.'),
action: payload =>
action: (payload) =>
dispatch('fetchJobs', payload).then(() =>
dispatch('setErrorMessage', null, { root: true }),
),
......
......@@ -23,7 +23,7 @@ export default {
yamlError: pipeline.yaml_errors,
};
state.stages = pipeline.details.stages.map((stage, i) => {
const foundStage = state.stages.find(s => s.id === i);
const foundStage = state.stages.find((s) => s.id === i);
return {
id: i,
dropdownPath: stage.dropdown_path,
......@@ -39,26 +39,26 @@ export default {
}
},
[types.REQUEST_JOBS](state, id) {
state.stages = state.stages.map(stage => ({
state.stages = state.stages.map((stage) => ({
...stage,
isLoading: stage.id === id ? true : stage.isLoading,
}));
},
[types.RECEIVE_JOBS_ERROR](state, id) {
state.stages = state.stages.map(stage => ({
state.stages = state.stages.map((stage) => ({
...stage,
isLoading: stage.id === id ? false : stage.isLoading,
}));
},
[types.RECEIVE_JOBS_SUCCESS](state, { id, data }) {
state.stages = state.stages.map(stage => ({
state.stages = state.stages.map((stage) => ({
...stage,
isLoading: stage.id === id ? false : stage.isLoading,
jobs: stage.id === id ? data.latest_statuses.map(normalizeJob) : stage.jobs,
}));
},
[types.TOGGLE_STAGE_COLLAPSE](state, id) {
state.stages = state.stages.map(stage => ({
state.stages = state.stages.map((stage) => ({
...stage,
isCollapsed: stage.id === id ? !stage.isCollapsed : stage.isCollapsed,
}));
......
export const normalizeJob = job => ({
export const normalizeJob = (job) => ({
id: job.id,
name: job.name,
status: job.status,
......
......@@ -36,7 +36,7 @@ export const fetchConfigCheck = ({ dispatch, rootState, rootGetters }) => {
.then(() => {
dispatch('receiveConfigCheckSuccess');
})
.catch(e => {
.catch((e) => {
dispatch('receiveConfigCheckError', e);
});
};
......@@ -92,7 +92,7 @@ export const fetchRunnersCheck = ({ dispatch, rootGetters }, options = {}) => {
.then(({ data }) => {
dispatch('receiveRunnersCheckSuccess', data);
})
.catch(e => {
.catch((e) => {
dispatch('receiveRunnersCheckError', e);
});
};
......@@ -45,7 +45,7 @@ export const startSession = ({ state, dispatch, rootGetters, rootState }) => {
.then(({ data }) => {
dispatch('receiveStartSessionSuccess', data);
})
.catch(error => {
.catch((error) => {
dispatch('receiveStartSessionError', error);
});
};
......@@ -73,7 +73,7 @@ export const stopSession = ({ state, dispatch }) => {
.then(() => {
dispatch('receiveStopSessionSuccess');
})
.catch(err => {
.catch((err) => {
dispatch('receiveStopSessionError', err);
});
};
......@@ -103,7 +103,7 @@ export const restartSession = ({ state, dispatch, rootState }) => {
.then(({ data }) => {
dispatch('receiveStartSessionSuccess', data);
})
.catch(error => {
.catch((error) => {
const responseStatus = error.response && error.response.status;
// We may have removed the build, in this case we'll just create a new session
if (
......
......@@ -58,7 +58,7 @@ export const fetchSessionStatus = ({ dispatch, state }) => {
.then(({ data }) => {
dispatch('receiveSessionStatusSuccess', data);
})
.catch(error => {
.catch((error) => {
dispatch('receiveSessionStatusError', error);
});
};
export const allCheck = state => {
export const allCheck = (state) => {
const checks = Object.values(state.checks);
if (checks.some(check => check.isLoading)) {
if (checks.some((check) => check.isLoading)) {
return { isLoading: true };
}
const invalidCheck = checks.find(check => !check.isValid);
const invalidCheck = checks.find((check) => !check.isValid);
const isValid = !invalidCheck;
const message = !invalidCheck ? '' : invalidCheck.message;
......
......@@ -46,7 +46,7 @@ export const configCheckError = (status, helpUrl) => {
return UNEXPECTED_ERROR_CONFIG;
};
export const runnersCheckEmpty = helpUrl =>
export const runnersCheckEmpty = (helpUrl) =>
sprintf(
EMPTY_RUNNERS,
{
......
import { STARTING, PENDING, RUNNING } from './constants';
export const isStartingStatus = status => status === STARTING || status === PENDING;
export const isRunningStatus = status => status === RUNNING;
export const isEndingStatus = status => !isStartingStatus(status) && !isRunningStatus(status);
export const isStartingStatus = (status) => status === STARTING || status === PENDING;
export const isRunningStatus = (status) => status === RUNNING;
export const isEndingStatus = (status) => !isStartingStatus(status) && !isRunningStatus(status);
......@@ -9,7 +9,7 @@ export const upload = ({ rootState, commit }) => {
.then(() => {
commit(types.SET_SUCCESS);
})
.catch(err => {
.catch((err) => {
commit(types.SET_ERROR, err);
});
};
......@@ -34,7 +34,7 @@ export const start = ({ rootState, commit }) => {
.then(() => {
commit(types.SET_SUCCESS);
})
.catch(err => {
.catch((err) => {
commit(types.SET_ERROR, err);
throw err;
});
......
......@@ -61,7 +61,7 @@ export default {
});
} else {
const tree = entry.tree.filter(
f => foundEntry.tree.find(e => e.path === f.path) === undefined,
(f) => foundEntry.tree.find((e) => e.path === f.path) === undefined,
);
Object.assign(foundEntry, {
tree: sortTree(foundEntry.tree.concat(tree)),
......@@ -72,7 +72,7 @@ export default {
}, []);
const currentTree = state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
const foundEntry = currentTree.tree.find(e => e.path === data.treeList[0].path);
const foundEntry = currentTree.tree.find((e) => e.path === data.treeList[0].path);
if (!foundEntry) {
Object.assign(currentTree, {
......@@ -125,7 +125,7 @@ export default {
});
},
[types.UPDATE_FILE_AFTER_COMMIT](state, { file, lastCommit }) {
const changedFile = state.changedFiles.find(f => f.path === file.path);
const changedFile = state.changedFiles.find((f) => f.path === file.path);
const { prevPath } = file;
Object.assign(state.entries[file.path], {
......@@ -172,7 +172,7 @@ export default {
entry.deleted = true;
if (parent) {
parent.tree = parent.tree.filter(f => f.path !== entry.path);
parent.tree = parent.tree.filter((f) => f.path !== entry.path);
}
if (entry.type === 'blob') {
......@@ -181,8 +181,8 @@ export default {
// changed and staged. Otherwise, we'd need to somehow evaluate the difference between
// changed and HEAD.
// https://gitlab.com/gitlab-org/create-stage/-/issues/12669
state.changedFiles = state.changedFiles.filter(f => f.path !== path);
state.stagedFiles = state.stagedFiles.filter(f => f.path !== path);
state.changedFiles = state.changedFiles.filter((f) => f.path !== path);
state.stagedFiles = state.stagedFiles.filter((f) => f.path !== path);
} else {
state.changedFiles = state.changedFiles.concat(entry);
}
......
......@@ -12,7 +12,7 @@ export default {
if (active && !state.entries[path].pending) {
Object.assign(state, {
openFiles: state.openFiles.map(f =>
openFiles: state.openFiles.map((f) =>
Object.assign(f, { active: f.pending ? false : f.active }),
),
});
......@@ -28,21 +28,21 @@ export default {
if (entry.opened) {
Object.assign(state, {
openFiles: state.openFiles.filter(f => f.path !== path).concat(state.entries[path]),
openFiles: state.openFiles.filter((f) => f.path !== path).concat(state.entries[path]),
});
} else {
Object.assign(state, {
openFiles: state.openFiles.filter(f => f.key !== entry.key),
openFiles: state.openFiles.filter((f) => f.key !== entry.key),
});
}
},
[types.SET_FILE_DATA](state, { data, file }) {
const stateEntry = state.entries[file.path];
const stagedFile = state.stagedFiles.find(f => f.path === file.path);
const openFile = state.openFiles.find(f => f.path === file.path);
const changedFile = state.changedFiles.find(f => f.path === file.path);
const stagedFile = state.stagedFiles.find((f) => f.path === file.path);
const openFile = state.openFiles.find((f) => f.path === file.path);
const changedFile = state.changedFiles.find((f) => f.path === file.path);
[stateEntry, stagedFile, openFile, changedFile].forEach(f => {
[stateEntry, stagedFile, openFile, changedFile].forEach((f) => {
if (f) {
Object.assign(
f,
......@@ -57,10 +57,10 @@ export default {
},
[types.SET_FILE_RAW_DATA](state, { file, raw, fileDeletedAndReadded = false }) {
const openPendingFile = state.openFiles.find(
f =>
(f) =>
f.path === file.path && f.pending && !(f.tempFile && !f.prevPath && !fileDeletedAndReadded),
);
const stagedFile = state.stagedFiles.find(f => f.path === file.path);
const stagedFile = state.stagedFiles.find((f) => f.path === file.path);
if (file.tempFile && file.content === '' && !fileDeletedAndReadded) {
Object.assign(state.entries[file.path], { content: raw });
......@@ -86,7 +86,7 @@ export default {
});
},
[types.UPDATE_FILE_CONTENT](state, { path, content }) {
const stagedFile = state.stagedFiles.find(f => f.path === path);
const stagedFile = state.stagedFiles.find((f) => f.path === path);
const rawContent = stagedFile ? stagedFile.content : state.entries[path].raw;
const changed = content !== rawContent;
......@@ -112,7 +112,7 @@ export default {
});
},
[types.DISCARD_FILE_CHANGES](state, path) {
const stagedFile = state.stagedFiles.find(f => f.path === path);
const stagedFile = state.stagedFiles.find((f) => f.path === path);
const entry = state.entries[path];
const { deleted } = entry;
......@@ -137,14 +137,14 @@ export default {
},
[types.REMOVE_FILE_FROM_CHANGED](state, path) {
Object.assign(state, {
changedFiles: state.changedFiles.filter(f => f.path !== path),
changedFiles: state.changedFiles.filter((f) => f.path !== path),
});
},
[types.STAGE_CHANGE](state, { path, diffInfo }) {
const stagedFile = state.stagedFiles.find(f => f.path === path);
const stagedFile = state.stagedFiles.find((f) => f.path === path);
Object.assign(state, {
changedFiles: state.changedFiles.filter(f => f.path !== path),
changedFiles: state.changedFiles.filter((f) => f.path !== path),
entries: Object.assign(state.entries, {
[path]: Object.assign(state.entries[path], {
staged: diffInfo.exists,
......@@ -162,12 +162,12 @@ export default {
}
if (!diffInfo.exists) {
state.stagedFiles = state.stagedFiles.filter(f => f.path !== path);
state.stagedFiles = state.stagedFiles.filter((f) => f.path !== path);
}
},
[types.UNSTAGE_CHANGE](state, { path, diffInfo }) {
const changedFile = state.changedFiles.find(f => f.path === path);
const stagedFile = state.stagedFiles.find(f => f.path === path);
const changedFile = state.changedFiles.find((f) => f.path === path);
const stagedFile = state.stagedFiles.find((f) => f.path === path);
if (!changedFile && stagedFile) {
Object.assign(state.entries[path], {
......@@ -182,11 +182,11 @@ export default {
}
if (!diffInfo.exists) {
state.changedFiles = state.changedFiles.filter(f => f.path !== path);
state.changedFiles = state.changedFiles.filter((f) => f.path !== path);
}
Object.assign(state, {
stagedFiles: state.stagedFiles.filter(f => f.path !== path),
stagedFiles: state.stagedFiles.filter((f) => f.path !== path),
entries: Object.assign(state.entries, {
[path]: Object.assign(state.entries[path], {
staged: false,
......@@ -206,7 +206,7 @@ export default {
state.entries[file.path].opened = false;
state.entries[file.path].active = false;
state.entries[file.path].lastOpenedAt = new Date().getTime();
state.openFiles.forEach(f =>
state.openFiles.forEach((f) =>
Object.assign(f, {
opened: false,
active: false,
......@@ -224,13 +224,13 @@ export default {
},
[types.REMOVE_PENDING_TAB](state, file) {
Object.assign(state, {
openFiles: state.openFiles.filter(f => f.key !== file.key),
openFiles: state.openFiles.filter((f) => f.key !== file.key),
});
},
[types.REMOVE_FILE_FROM_STAGED_AND_CHANGED](state, file) {
Object.assign(state, {
changedFiles: state.changedFiles.filter(f => f.key !== file.key),
stagedFiles: state.stagedFiles.filter(f => f.key !== file.key),
changedFiles: state.changedFiles.filter((f) => f.key !== file.key),
stagedFiles: state.stagedFiles.filter((f) => f.key !== file.key),
});
Object.assign(state.entries[file.path], {
......
......@@ -45,7 +45,7 @@ export default {
? state.entries[entry.parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
if (!parent.tree.find(f => f.path === path)) {
if (!parent.tree.find((f) => f.path === path)) {
parent.tree = sortTree(parent.tree.concat(entry));
}
},
......
......@@ -11,7 +11,7 @@ function getPathsFromData(el) {
}
export default function createTerminalPlugin(el) {
return store => {
return (store) => {
store.registerModule('terminal', terminalModule());
store.dispatch('terminal/setPaths', getPathsFromData(el));
......
......@@ -12,7 +12,7 @@ const UPLOAD_DEBOUNCE = 200;
* - Listens for file change event to control upload.
*/
export default function createMirrorPlugin() {
return store => {
return (store) => {
store.registerModule('terminalSync', terminalSyncModule());
const upload = debounce(() => {
......@@ -36,8 +36,8 @@ export default function createMirrorPlugin() {
};
store.watch(
x => x.terminal && x.terminal.session && x.terminal.session.status,
val => {
(x) => x.terminal && x.terminal.session && x.terminal.session.status,
(val) => {
if (isRunningStatus(val)) {
start();
} else if (isEndingStatus(val)) {
......
......@@ -34,7 +34,7 @@ export const dataStructure = () => ({
mimeType: '',
});
export const decorateData = entity => {
export const decorateData = (entity) => {
const {
id,
type,
......@@ -69,7 +69,7 @@ export const decorateData = entity => {
});
};
export const setPageTitle = title => {
export const setPageTitle = (title) => {
document.title = title;
};
......@@ -78,7 +78,7 @@ export const setPageTitleForFile = (state, file) => {
setPageTitle(title);
};
export const commitActionForFile = file => {
export const commitActionForFile = (file) => {
if (file.prevPath) {
return commitActionTypes.move;
} else if (file.deleted) {
......@@ -90,7 +90,7 @@ export const commitActionForFile = file => {
return commitActionTypes.update;
};
export const getCommitFiles = stagedFiles =>
export const getCommitFiles = (stagedFiles) =>
stagedFiles.reduce((acc, file) => {
if (file.type === 'tree') return acc;
......@@ -109,7 +109,7 @@ export const createCommitPayload = ({
}) => ({
branch,
commit_message: state.commitMessage || getters.preBuiltCommitMessage,
actions: getCommitFiles(rootState.stagedFiles).map(f => {
actions: getCommitFiles(rootState.stagedFiles).map((f) => {
const isBlob = isBlobUrl(f.rawPath);
const content = isBlob ? btoa(f.content) : f.content;
......@@ -139,9 +139,9 @@ const sortTreesByTypeAndName = (a, b) => {
return 0;
};
export const sortTree = sortedTree =>
export const sortTree = (sortedTree) =>
sortedTree
.map(entity =>
.map((entity) =>
Object.assign(entity, {
tree: entity.tree.length ? sortTree(entity.tree) : [],
}),
......@@ -151,7 +151,7 @@ export const sortTree = sortedTree =>
export const filePathMatches = (filePath, path) => filePath.indexOf(`${path}/`) === 0;
export const getChangesCountForFiles = (files, path) =>
files.filter(f => filePathMatches(f.path, path)).length;
files.filter((f) => filePathMatches(f.path, path)).length;
export const mergeTrees = (fromTree, toTree) => {
if (!fromTree || !fromTree.length) {
......@@ -162,7 +162,7 @@ export const mergeTrees = (fromTree, toTree) => {
if (!n) {
return t;
}
const existingTreeNode = t.find(el => el.path === n.path);
const existingTreeNode = t.find((el) => el.path === n.path);
if (existingTreeNode && n.tree.length > 0) {
existingTreeNode.opened = true;
......@@ -183,7 +183,7 @@ export const mergeTrees = (fromTree, toTree) => {
export const swapInStateArray = (state, arr, key, entryPath) =>
Object.assign(state, {
[arr]: state[arr].map(f => (f.key === key ? state.entries[entryPath] : f)),
[arr]: state[arr].map((f) => (f.key === key ? state.entries[entryPath] : f)),
});
export const getEntryOrRoot = (state, path) =>
......@@ -216,12 +216,12 @@ export const removeFromParentTree = (state, oldKey, parentPath) => {
};
export const updateFileCollections = (state, key, entryPath) => {
['openFiles', 'changedFiles', 'stagedFiles'].forEach(fileCollection => {
['openFiles', 'changedFiles', 'stagedFiles'].forEach((fileCollection) => {
swapInStateArray(state, fileCollection, key, entryPath);
});
};
export const cleanTrailingSlash = path => path.replace(/\/$/, '');
export const cleanTrailingSlash = (path) => path.replace(/\/$/, '');
export const pathsAreEqual = (a, b) => {
const cleanA = a ? cleanTrailingSlash(a) : '';
......
......@@ -21,8 +21,8 @@ export const syncRouterAndStore = (router, store) => {
// sync store to router
disposables.push(
store.watch(
state => state.router.fullPath,
fullPath => {
(state) => state.router.fullPath,
(fullPath) => {
if (currentPath === fullPath) {
return;
}
......@@ -36,7 +36,7 @@ export const syncRouterAndStore = (router, store) => {
// sync router to store
disposables.push(
router.afterEach(to => {
router.afterEach((to) => {
if (currentPath === to.fullPath) {
return;
}
......@@ -47,7 +47,7 @@ export const syncRouterAndStore = (router, store) => {
);
const unsync = () => {
disposables.forEach(fn => fn());
disposables.forEach((fn) => fn());
};
return unsync;
......
......@@ -3,17 +3,17 @@ import { flatten, isString } from 'lodash';
import { SIDE_LEFT, SIDE_RIGHT } from './constants';
import { performanceMarkAndMeasure } from '~/performance/utils';
const toLowerCase = x => x.toLowerCase();
const toLowerCase = (x) => x.toLowerCase();
const monacoLanguages = languages.getLanguages();
const monacoExtensions = new Set(
flatten(monacoLanguages.map(lang => lang.extensions?.map(toLowerCase) || [])),
flatten(monacoLanguages.map((lang) => lang.extensions?.map(toLowerCase) || [])),
);
const monacoMimetypes = new Set(
flatten(monacoLanguages.map(lang => lang.mimetypes?.map(toLowerCase) || [])),
flatten(monacoLanguages.map((lang) => lang.mimetypes?.map(toLowerCase) || [])),
);
const monacoFilenames = new Set(
flatten(monacoLanguages.map(lang => lang.filenames?.map(toLowerCase) || [])),
flatten(monacoLanguages.map((lang) => lang.filenames?.map(toLowerCase) || [])),
);
const KNOWN_TYPES = [
......@@ -44,7 +44,7 @@ const KNOWN_TYPES = [
];
export function isTextFile({ name, raw, content, mimeType = '' }) {
const knownType = KNOWN_TYPES.find(type => type.isMatch(mimeType, name));
const knownType = KNOWN_TYPES.find((type) => type.isMatch(mimeType, name));
if (knownType) return knownType.isText;
// does the string contain ascii characters only (ranges from space to tilde, tabs and new lines)
......@@ -56,20 +56,20 @@ export function isTextFile({ name, raw, content, mimeType = '' }) {
return isString(fileContents) && (fileContents === '' || asciiRegex.test(fileContents));
}
export const createPathWithExt = p => {
export const createPathWithExt = (p) => {
const ext = p.lastIndexOf('.') >= 0 ? p.substring(p.lastIndexOf('.') + 1) : '';
return `${p.substring(1, p.lastIndexOf('.') + 1 || p.length)}${ext || '.js'}`;
};
export const trimPathComponents = path =>
export const trimPathComponents = (path) =>
path
.split('/')
.map(s => s.trim())
.map((s) => s.trim())
.join('/');
export function registerLanguages(def, ...defs) {
defs.forEach(lang => registerLanguages(lang));
defs.forEach((lang) => registerLanguages(lang));
const languageId = def.id;
......@@ -80,7 +80,7 @@ export function registerLanguages(def, ...defs) {
export function registerSchema(schema) {
const defaults = [languages.json.jsonDefaults, languages.yaml.yamlDefaults];
defaults.forEach(d =>
defaults.forEach((d) =>
d.setDiagnosticsOptions({
validate: true,
enableSchemaRequest: true,
......@@ -91,7 +91,7 @@ export function registerSchema(schema) {
);
}
export const otherSide = side => (side === SIDE_RIGHT ? SIDE_LEFT : SIDE_RIGHT);
export const otherSide = (side) => (side === SIDE_RIGHT ? SIDE_LEFT : SIDE_RIGHT);
export function trimTrailingWhitespace(content) {
return content.replace(/[^\S\r\n]+$/gm, '');
......@@ -125,9 +125,9 @@ export function getPathParent(path) {
* @param {File} file
*/
export function readFileAsDataURL(file) {
return new Promise(resolve => {
return new Promise((resolve) => {
const reader = new FileReader();
reader.addEventListener('load', e => resolve(e.target.result), { once: true });
reader.addEventListener('load', (e) => resolve(e.target.result), { once: true });
reader.readAsDataURL(file);
});
}
......
......@@ -3,7 +3,7 @@ import { spriteIcon } from '~/lib/utils/common_utils';
export function createImageBadge(noteId, { x, y }, classNames = []) {
const buttonEl = document.createElement('button');
const classList = classNames.concat(['js-image-badge']);
classList.forEach(className => buttonEl.classList.add(className));
classList.forEach((className) => buttonEl.classList.add(className));
buttonEl.setAttribute('type', 'button');
buttonEl.setAttribute('disabled', true);
buttonEl.dataset.noteId = noteId;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment