mirror of
https://github.com/CringeStudios/element-desktop.git
synced 2025-01-31 05:29:58 +01:00
Merge pull request #197 from vector-im/jryans/rework-linting
Migrate to `eslint-plugin-matrix-org`
This commit is contained in:
commit
7f28e3f1e2
13
.eslintrc.js
13
.eslintrc.js
@ -1,6 +1,12 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
plugins: [
|
||||||
|
"matrix-org",
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
"plugin:matrix-org/javascript",
|
||||||
|
],
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
ecmaVersion: 8,
|
ecmaVersion: 2021,
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
es6: true,
|
es6: true,
|
||||||
@ -8,12 +14,7 @@ module.exports = {
|
|||||||
// we also have some browser code (ie. the preload script)
|
// we also have some browser code (ie. the preload script)
|
||||||
browser: true,
|
browser: true,
|
||||||
},
|
},
|
||||||
extends: ["matrix-org"],
|
|
||||||
rules: {
|
rules: {
|
||||||
// js-sdk uses a babel rule which we can't use because we
|
|
||||||
// don't use babel, so remove it & put the original back
|
|
||||||
"babel/no-invalid-this": "off",
|
|
||||||
"no-invalid-this": "error",
|
|
||||||
"quotes": "off",
|
"quotes": "off",
|
||||||
"indent": "off",
|
"indent": "off",
|
||||||
"prefer-promise-reject-errors": "off",
|
"prefer-promise-reject-errors": "off",
|
||||||
|
@ -47,8 +47,9 @@
|
|||||||
"electron-builder-squirrel-windows": "22.10.5",
|
"electron-builder-squirrel-windows": "22.10.5",
|
||||||
"electron-devtools-installer": "^3.1.1",
|
"electron-devtools-installer": "^3.1.1",
|
||||||
"electron-notarize": "^1.0.0",
|
"electron-notarize": "^1.0.0",
|
||||||
"eslint": "7.3.1",
|
"eslint": "7.18.0",
|
||||||
"eslint-config-matrix-org": "^0.1.2",
|
"eslint-config-google": "^0.14.0",
|
||||||
|
"eslint-plugin-matrix-org": "github:matrix-org/eslint-plugin-matrix-org#main",
|
||||||
"find-npm-prefix": "^1.0.2",
|
"find-npm-prefix": "^1.0.2",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"glob": "^7.1.6",
|
"glob": "^7.1.6",
|
||||||
|
@ -15,7 +15,7 @@ const PUB_KEY_URL = "https://packages.riot.im/element-release-key.asc";
|
|||||||
const PACKAGE_URL_PREFIX = "https://github.com/vector-im/element-web/releases/download/";
|
const PACKAGE_URL_PREFIX = "https://github.com/vector-im/element-web/releases/download/";
|
||||||
const ASAR_PATH = 'webapp.asar';
|
const ASAR_PATH = 'webapp.asar';
|
||||||
|
|
||||||
const {setPackageVersion} = require('./set-version.js');
|
const { setPackageVersion } = require('./set-version.js');
|
||||||
|
|
||||||
async function getLatestDevelopUrl(bkToken) {
|
async function getLatestDevelopUrl(bkToken) {
|
||||||
const buildsResult = await needle('get',
|
const buildsResult = await needle('get',
|
||||||
|
@ -37,7 +37,7 @@ async function fetch(hakEnv, moduleInfo) {
|
|||||||
if (haveModuleBuildDir) return;
|
if (haveModuleBuildDir) return;
|
||||||
|
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
npm.load({'loglevel': 'silent'}, resolve);
|
npm.load({ 'loglevel': 'silent' }, resolve);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Fetching " + moduleInfo.name + " at version " + moduleInfo.version);
|
console.log("Fetching " + moduleInfo.name + " at version " + moduleInfo.version);
|
||||||
|
@ -52,4 +52,4 @@ if (require.main === module) {
|
|||||||
main(process.argv.slice(2)).then((ret) => process.exit(ret));
|
main(process.argv.slice(2)).then((ret) => process.exit(ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {versionFromAsar, setPackageVersion};
|
module.exports = { versionFromAsar, setPackageVersion };
|
||||||
|
@ -24,7 +24,7 @@ const checkSquirrelHooks = require('./squirrelhooks');
|
|||||||
if (checkSquirrelHooks()) return;
|
if (checkSquirrelHooks()) return;
|
||||||
|
|
||||||
const argv = require('minimist')(process.argv, {
|
const argv = require('minimist')(process.argv, {
|
||||||
alias: {help: "h"},
|
alias: { help: "h" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -37,7 +37,7 @@ const tray = require('./tray');
|
|||||||
const buildMenuTemplate = require('./vectormenu');
|
const buildMenuTemplate = require('./vectormenu');
|
||||||
const webContentsHandler = require('./webcontents-handler');
|
const webContentsHandler = require('./webcontents-handler');
|
||||||
const updater = require('./updater');
|
const updater = require('./updater');
|
||||||
const {getProfileFromDeeplink, protocolInit, recordSSOSession} = require('./protocol');
|
const { getProfileFromDeeplink, protocolInit, recordSSOSession } = require('./protocol');
|
||||||
|
|
||||||
const windowStateKeeper = require('electron-window-state');
|
const windowStateKeeper = require('electron-window-state');
|
||||||
const Store = require('electron-store');
|
const Store = require('electron-store');
|
||||||
@ -499,7 +499,6 @@ ipcMain.on('ipcCall', async function(ev, payload) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const seshatDefaultPassphrase = "DEFAULT_PASSPHRASE";
|
const seshatDefaultPassphrase = "DEFAULT_PASSPHRASE";
|
||||||
async function getOrCreatePassphrase(key) {
|
async function getOrCreatePassphrase(key) {
|
||||||
if (keytar) {
|
if (keytar) {
|
||||||
@ -551,8 +550,8 @@ ipcMain.on('seshat', async function(ev, payload) {
|
|||||||
const passphrase = await getOrCreatePassphrase(passphraseKey);
|
const passphrase = await getOrCreatePassphrase(passphraseKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await afs.mkdir(eventStorePath, {recursive: true});
|
await afs.mkdir(eventStorePath, { recursive: true });
|
||||||
eventIndex = new Seshat(eventStorePath, {passphrase});
|
eventIndex = new Seshat(eventStorePath, { passphrase });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ReindexError) {
|
if (e instanceof ReindexError) {
|
||||||
// If this is a reindex error, the index schema
|
// If this is a reindex error, the index schema
|
||||||
@ -578,7 +577,7 @@ ipcMain.on('seshat', async function(ev, payload) {
|
|||||||
await recoveryIndex.reindex();
|
await recoveryIndex.reindex();
|
||||||
}
|
}
|
||||||
|
|
||||||
eventIndex = new Seshat(eventStorePath, {passphrase});
|
eventIndex = new Seshat(eventStorePath, { passphrase });
|
||||||
} else {
|
} else {
|
||||||
sendError(payload.id, e);
|
sendError(payload.id, e);
|
||||||
return;
|
return;
|
||||||
@ -836,17 +835,17 @@ app.on('ready', async () => {
|
|||||||
|
|
||||||
protocol.registerFileProtocol('vector', (request, callback) => {
|
protocol.registerFileProtocol('vector', (request, callback) => {
|
||||||
if (request.method !== 'GET') {
|
if (request.method !== 'GET') {
|
||||||
callback({error: -322}); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h
|
callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedUrl = new URL(request.url);
|
const parsedUrl = new URL(request.url);
|
||||||
if (parsedUrl.protocol !== 'vector:') {
|
if (parsedUrl.protocol !== 'vector:') {
|
||||||
callback({error: -302}); // UNKNOWN_URL_SCHEME
|
callback({ error: -302 }); // UNKNOWN_URL_SCHEME
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parsedUrl.host !== 'vector') {
|
if (parsedUrl.host !== 'vector') {
|
||||||
callback({error: -105}); // NAME_NOT_RESOLVED
|
callback({ error: -105 }); // NAME_NOT_RESOLVED
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -854,7 +853,7 @@ app.on('ready', async () => {
|
|||||||
|
|
||||||
// path starts with a '/'
|
// path starts with a '/'
|
||||||
if (target[0] !== '') {
|
if (target[0] !== '') {
|
||||||
callback({error: -6}); // FILE_NOT_FOUND
|
callback({ error: -6 }); // FILE_NOT_FOUND
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -866,7 +865,7 @@ app.on('ready', async () => {
|
|||||||
if (target[1] === 'webapp') {
|
if (target[1] === 'webapp') {
|
||||||
baseDir = asarPath;
|
baseDir = asarPath;
|
||||||
} else {
|
} else {
|
||||||
callback({error: -6}); // FILE_NOT_FOUND
|
callback({ error: -6 }); // FILE_NOT_FOUND
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -876,7 +875,7 @@ app.on('ready', async () => {
|
|||||||
|
|
||||||
const relTarget = path.normalize(path.join(...target.slice(2)));
|
const relTarget = path.normalize(path.join(...target.slice(2)));
|
||||||
if (relTarget.startsWith('..')) {
|
if (relTarget.startsWith('..')) {
|
||||||
callback({error: -6}); // FILE_NOT_FOUND
|
callback({ error: -6 }); // FILE_NOT_FOUND
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const absTarget = path.join(baseDir, relTarget);
|
const absTarget = path.join(baseDir, relTarget);
|
||||||
|
@ -48,7 +48,7 @@ function _t(text, variables = {}) {
|
|||||||
if (translated === undefined && count !== undefined) {
|
if (translated === undefined && count !== undefined) {
|
||||||
// counterpart does not do fallback if no pluralisation exists
|
// counterpart does not do fallback if no pluralisation exists
|
||||||
// in the preferred language, so do it here
|
// in the preferred language, so do it here
|
||||||
translated = counterpart.translate(text, Object.assign({}, args, {locale: DEFAULT_LOCALE}));
|
translated = counterpart.translate(text, Object.assign({}, args, { locale: DEFAULT_LOCALE }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The translation returns text so there's no XSS vector here (no unsafe HTML, no code execution)
|
// The translation returns text so there's no XSS vector here (no unsafe HTML, no code execution)
|
||||||
@ -56,10 +56,10 @@ function _t(text, variables = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AppLocalization {
|
class AppLocalization {
|
||||||
static STORE_KEY = "locale"
|
|
||||||
store = null
|
|
||||||
|
|
||||||
constructor({ store, components = [] }) {
|
constructor({ store, components = [] }) {
|
||||||
|
// TODO: Should be static field, but that doesn't parse without Babel
|
||||||
|
this.STORE_KEY = "locale";
|
||||||
|
|
||||||
counterpart.registerTranslations("en", this.fetchTranslationJson("en_EN"));
|
counterpart.registerTranslations("en", this.fetchTranslationJson("en_EN"));
|
||||||
counterpart.setFallbackLocale('en');
|
counterpart.setFallbackLocale('en');
|
||||||
counterpart.setSeparator('|');
|
counterpart.setSeparator('|');
|
||||||
@ -69,8 +69,8 @@ class AppLocalization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.store = store;
|
this.store = store;
|
||||||
if (this.store.has(AppLocalization.STORE_KEY)) {
|
if (this.store.has(this.STORE_KEY)) {
|
||||||
const locales = this.store.get(AppLocalization.STORE_KEY);
|
const locales = this.store.get(this.STORE_KEY);
|
||||||
this.setAppLocale(locales);
|
this.setAppLocale(locales);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class AppLocalization {
|
|||||||
});
|
});
|
||||||
|
|
||||||
counterpart.setLocale(locales);
|
counterpart.setLocale(locales);
|
||||||
this.store.set(AppLocalization.STORE_KEY, locales);
|
this.store.set(this.STORE_KEY, locales);
|
||||||
|
|
||||||
this.resetLocalizedUI();
|
this.resetLocalizedUI();
|
||||||
}
|
}
|
||||||
@ -121,7 +121,6 @@ class AppLocalization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
AppLocalization,
|
AppLocalization,
|
||||||
_t,
|
_t,
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {app} = require("electron");
|
const { app } = require("electron");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const {app} = require('electron');
|
const { app } = require('electron');
|
||||||
const fsProm = require('fs').promises;
|
const fsProm = require('fs').promises;
|
||||||
|
|
||||||
function runUpdateExe(args) {
|
function runUpdateExe(args) {
|
||||||
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {app, Tray, Menu, nativeImage} = require('electron');
|
const { app, Tray, Menu, nativeImage } = require('electron');
|
||||||
const pngToIco = require('png-to-ico');
|
const pngToIco = require('png-to-ico');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {app, shell, Menu} = require('electron');
|
const { app, shell, Menu } = require('electron');
|
||||||
const { _t } = require('./language-helper');
|
const { _t } = require('./language-helper');
|
||||||
|
|
||||||
function buildMenuTemplate() {
|
function buildMenuTemplate() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const {clipboard, nativeImage, Menu, MenuItem, shell, dialog, ipcMain} = require('electron');
|
const { clipboard, nativeImage, Menu, MenuItem, shell, dialog, ipcMain } = require('electron');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
@ -50,7 +50,6 @@ function writeNativeImage(filePath, img) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function onLinkContextMenu(ev, params) {
|
function onLinkContextMenu(ev, params) {
|
||||||
let url = params.linkURL || params.srcURL;
|
let url = params.linkURL || params.srcURL;
|
||||||
|
|
||||||
@ -112,7 +111,7 @@ function onLinkContextMenu(ev, params) {
|
|||||||
accelerator: 'a',
|
accelerator: 'a',
|
||||||
async click() {
|
async click() {
|
||||||
const targetFileName = params.titleText || "image.png";
|
const targetFileName = params.titleText || "image.png";
|
||||||
const {filePath} = await dialog.showSaveDialog({
|
const { filePath } = await dialog.showSaveDialog({
|
||||||
defaultPath: targetFileName,
|
defaultPath: targetFileName,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -215,7 +214,7 @@ function onEditableContextMenu(ev, params) {
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('userDownloadOpen', function(ev, {path}) {
|
ipcMain.on('userDownloadOpen', function(ev, { path }) {
|
||||||
shell.openPath(path);
|
shell.openPath(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user