Skip to content

Commit

Permalink
refactor: replace indexOf with includes/startsWith where applicable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Dec 12, 2019
1 parent 006d62f commit a3eae4d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/api/core/src/api/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default async ({
let possibleAssets: Asset[] = [];

await asyncOra('Searching for Application', async (searchSpinner) => {
if (!repo || repo.indexOf('/') === -1) {
if (!repo || !repo.includes('/')) {
throw new Error('Invalid repository name, must be in the format owner/name');
}

Expand Down
4 changes: 2 additions & 2 deletions packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default async ({
if ((target as MakerBase<any>).__isElectronForgeMaker) {
maker = target as MakerBase<any>;
// eslint-disable-next-line no-continue
if (maker.platforms.indexOf(actualTargetPlatform) === -1) continue;
if (!maker.platforms.includes(actualTargetPlatform)) continue;
} else {
const resolvableTarget: IForgeResolvableMaker = target as IForgeResolvableMaker;
const MakerClass = requireSearch<typeof MakerImpl>(dir, [resolvableTarget.name]);
Expand All @@ -114,7 +114,7 @@ export default async ({

maker = new MakerClass(resolvableTarget.config, resolvableTarget.platforms || undefined);
// eslint-disable-next-line no-continue
if (maker.platforms.indexOf(actualTargetPlatform) === -1) continue;
if (!maker.platforms.includes(actualTargetPlatform)) continue;
}

if (!maker.isSupportedOnCurrentPlatform) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/api/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const publish = async ({
if (!publishTargets) {
publishTargets = (forgeConfig.publishers || []);
// .filter(publisher => (typeof publisher !== 'string' && publisher.platforms)
// ? publisher.platforms.indexOf(testPlatform) !== -1 : true);
// ? publisher.platforms.includes(testPlatform) : true);
}
publishTargets = (publishTargets as ForgeConfigPublisher[]).map((target) => {
if (typeof target === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/test/fast/publish_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe('publish', () => {
it('should successfully restore values and pass them to publisher', () => {
expect(makeStub.callCount).to.equal(0);
expect(publisherSpy.callCount).to.equal(2, 'should call once for each platform (make run)');
const darwinIndex = publisherSpy.firstCall.args[0].makeResults[0].artifacts.some((a: string) => a.indexOf('darwin') !== -1) ? 0 : 1;
const darwinIndex = publisherSpy.firstCall.args[0].makeResults[0].artifacts.some((a: string) => a.includes('darwin')) ? 0 : 1;
const win32Index = darwinIndex === 0 ? 1 : 0;
const darwinArgs = publisherSpy.getCall(darwinIndex).args[0];
const darwinArtifacts = [];
Expand Down
7 changes: 2 additions & 5 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe
getDefines = (inRendererDir = true) => {
const defines: { [key: string]: string; } = {
ASSET_RELOCATOR_BASE_DIR: this.isProd
? `process.resourcesPath + "/" + (__filename.indexOf(".asar") === -1 ? "app" : "app.asar") + "/.webpack/${inRendererDir ? 'main' : 'renderer/any_folder'}"`
? `process.resourcesPath + "/" + (__filename.includes(".asar") ? "app.asar" : "app") + "/.webpack/${inRendererDir ? 'main' : 'renderer/any_folder'}"`
: JSON.stringify(
path.resolve(
this.baseDir,
Expand Down Expand Up @@ -259,10 +259,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe
const fix = (item: EntryType): EntryType => {
if (typeof item === 'string') return (fix([item]) as string[])[0];
if (Array.isArray(item)) {
return item.map((val) => {
if (val.indexOf('./') === 0) return path.resolve(this.projectDir, val);
return val;
});
return item.map((val) => (val.startsWith('./') ? path.resolve(this.projectDir, val) : val));
}
const ret: Record<string, string | string[]> = {};
for (const key of Object.keys(item)) {
Expand Down

0 comments on commit a3eae4d

Please sign in to comment.