Skip to content

Commit

Permalink
Merge pull request #1061 from chromaui/cody/cap-2227-enable-unicornpr…
Browse files Browse the repository at this point in the history
…efer-module

Enable `unicorn/prefer-module` ESLint rule
  • Loading branch information
codykaup authored Sep 30, 2024
2 parents aa83825 + 9fc7574 commit 83a81fe
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 8 deletions.
18 changes: 12 additions & 6 deletions bin-src/register.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */

require('dotenv').config();
import { config } from 'dotenv';

import { main as initMain } from './init';
import { main } from './main';
import { main as traceMain } from './trace';
import { main as trimMain } from './trim-stats-file';

config();

const commands = {
init: () => require('./init').main(process.argv.slice(3)),
main: () => require('./main').main(process.argv.slice(2)),
trace: () => require('./trace').main(process.argv.slice(3)),
'trim-stats-file': () => require('./trim-stats-file').main(process.argv.slice(3)),
init: () => initMain(process.argv.slice(3)),
main: () => main(process.argv.slice(2)),
trace: () => traceMain(process.argv.slice(3)),
'trim-stats-file': () => trimMain(process.argv.slice(3)),
};

(commands[process.argv[2]] || commands.main)();
2 changes: 0 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ export default [
'unicorn/switch-case-braces': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/prefer-node-protocol': 'off', // This will error our Webpack build
// TODO: remove the following lines when we are ready to enforce these rules
'unicorn/prefer-module': 'off',
},
},
// prefer TS to complain when we miss an arg vs. sending an intentional undefined
Expand Down
1 change: 1 addition & 0 deletions isChromatic.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/prefer-module */
/* eslint-env browser */

module.exports = function isChromatic(windowArgument) {
Expand Down
3 changes: 3 additions & 0 deletions node-src/lib/checkStorybookBaseDirectory.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import path from 'path';
import { fileURLToPath } from 'url';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import * as git from '../git/git';
import { checkStorybookBaseDirectory } from './checkStorybookBaseDirectory';
import { exitCodes } from './setExitCode';
import TestLogger from './testLogger';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

vi.mock('../git/git');

const getRepositoryRoot = vi.mocked(git.getRepositoryRoot);
Expand Down
3 changes: 3 additions & 0 deletions node-src/lib/compareBaseline.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import path from 'path';
import { fileURLToPath } from 'url';
import { describe, expect, it } from 'vitest';

import { compareBaseline } from './compareBaseline';
import { getDependencies } from './getDependencies';
import TestLogger from './testLogger';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const getContext: any = (baselineCommits: string[]) => ({
log: new TestLogger(),
git: { baselineCommits },
Expand Down
1 change: 1 addition & 0 deletions node-src/lib/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export async function getE2EBuildCommand(
try {
return [
'node',
// eslint-disable-next-line unicorn/prefer-module
require.resolve(`${dependencyName}/bin/${buildBinName}`),
...buildCommandOptions,
].join(' ');
Expand Down
3 changes: 3 additions & 0 deletions node-src/lib/getDependencies.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import path from 'path';
import { fileURLToPath } from 'url';
import { describe, expect, it } from 'vitest';

import packageJson from '../__mocks__/dependencyChanges/plain-package.json';
import { checkoutFile } from '../git/git';
import { getDependencies } from './getDependencies';
import TestLogger from './testLogger';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const ctx = { log: new TestLogger() } as any;

describe('getDependencies', () => {
Expand Down
1 change: 1 addition & 0 deletions node-src/lib/getStorybookMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export const findStorybookConfigFile = async (ctx: Context, pattern: RegExp) =>

export const getStorybookMetadata = async (ctx: Context) => {
const configDirectory = ctx.options.storybookConfigDir ?? '.storybook';
// eslint-disable-next-line unicorn/prefer-module
const r = typeof __non_webpack_require__ === 'undefined' ? require : __non_webpack_require__;

let mainConfig;
Expand Down
3 changes: 3 additions & 0 deletions node-src/tasks/report.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import reportBuilder from 'junit-report-builder';
import path from 'path';
import { fileURLToPath } from 'url';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { generateReport } from './report';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const log = { error: vi.fn(), info: vi.fn() };
const mockTests = [
{
Expand Down
1 change: 1 addition & 0 deletions test-stories/timing.stories-disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const WaitFor = ({ seconds }) => {
);
};

// eslint-disable-next-line unicorn/prefer-module
storiesOf('Timing', module)
.add('5s', () => <WaitFor seconds={5} />)
.add('40s', () => <WaitFor seconds={40} />)
Expand Down

0 comments on commit 83a81fe

Please sign in to comment.