Skip to content

Commit f24ede5

Browse files
author
Daniel Del Core
committed
fixes validate command error
1 parent 340d756 commit f24ede5

File tree

7 files changed

+32
-29
lines changed

7 files changed

+32
-29
lines changed

community/@atlaskit__textfield/src/5.0.0/__tests__/remove-imports.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ function transformer(
1515
return source.toSource(options.printOptions);
1616
}
1717

18-
const importToDoComment = `
19-
/* TODO: (@hypermod) This file uses exports used to help theme @atlaskit/textfield which
20-
has now been removed due to its poor performance characteristics. */`;
21-
2218
describe('Remove imports', () => {
2319
it('should remove theme imports from Textfield and leave a comment', async () => {
2420
const result = await applyTransform(

community/@atlaskit__textfield/src/5.0.0/__tests__/remove-prop.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ function transformer(
1515
return source.toSource(options.printOptions);
1616
}
1717

18-
const themeToDoComment = `
19-
/* TODO: (@hypermod) This file uses the @atlaskit/textfield \`theme\` prop which
20-
has now been removed due to its poor performance characteristics. We have not replaced
21-
theme with an equivalent API due to minimal usage of the \`theme\` prop.
22-
The appearance of TextField will have likely changed. */`;
23-
2418
describe('Remove prop', () => {
2519
it('should remove theme from Textfield and leave a comment', async () => {
2620
const result = await applyTransform(

community/hypermod/src/defineInlineTest-to-applyTransform/transform.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import core, { API, FileInfo, Options, Collection } from 'jscodeshift';
22

3-
import { hasImportDeclaration, hasImportSpecifier } from '@hypermod/utils';
3+
import { hasImportSpecifier } from '@hypermod/utils';
44

55
export default function transformer(
66
file: FileInfo,
@@ -102,8 +102,7 @@ function transformDefineInlineTestCalls(
102102
path.node.callee.property.name === 'defineInlineTest'),
103103
)
104104
.forEach(path => {
105-
const [transformerOpts, _configOpts, input, output, description] =
106-
path.node.arguments;
105+
const [transformerOpts, input, output, description] = path.node.arguments;
107106

108107
const transformer = j(transformerOpts).find(j.ObjectProperty, {
109108
key: { name: 'default' },

packages/fetcher/src/index.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ describe('fetcher', () => {
4242
{ virtual: true },
4343
);
4444

45-
const { filePath, config } = await fetchConfig(mockBasePath);
45+
const configMeta = await fetchConfig(mockBasePath);
4646

47-
expect(config).toEqual(mockConfig);
48-
expect(filePath).toEqual(mockFilePath);
47+
expect(configMeta!.config).toEqual(mockConfig);
48+
expect(configMeta!.filePath).toEqual(mockFilePath);
4949
});
5050

5151
it('fetches config with named export', async () => {
@@ -57,10 +57,12 @@ describe('fetcher', () => {
5757
},
5858
);
5959

60-
const { filePath, config } = await fetchConfig(mockBasePath);
60+
const configMeta = await fetchConfig(mockBasePath);
6161

62-
expect(config).toEqual(mockConfig);
63-
expect(filePath).toEqual(path.join(mockBasePath, 'hypermod.config.js'));
62+
expect(configMeta!.config).toEqual(mockConfig);
63+
expect(configMeta!.filePath).toEqual(
64+
path.join(mockBasePath, 'hypermod.config.js'),
65+
);
6466
});
6567

6668
it('fetches first matched config when multiple are found', async () => {
@@ -81,10 +83,10 @@ describe('fetcher', () => {
8183
path.join(mockBasePath, 'codemods', 'hypermod.config.tsx'),
8284
];
8385

84-
const { config, filePath } = await fetchConfig(mockBasePath);
86+
const configMeta = await fetchConfig(mockBasePath);
8587

86-
expect(config).toEqual(mockConfig);
87-
expect(filePath).toEqual(
88+
expect(configMeta!.config).toEqual(mockConfig);
89+
expect(configMeta!.filePath).toEqual(
8890
path.join(mockBasePath, 'src', 'hypermod.config.ts'),
8991
);
9092
});

packages/fetcher/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ function requireConfig(filePath: string, resolvedPath: string) {
2828
}
2929
}
3030

31-
export async function fetchConfig(filePath: string): Promise<ConfigMeta> {
31+
export async function fetchConfig(
32+
filePath: string,
33+
): Promise<ConfigMeta | undefined> {
3234
const configs = await fetchConfigs(filePath);
3335
return configs[0];
3436
}
@@ -94,7 +96,7 @@ export async function fetchPackage(
9496
export async function fetchRemotePackage(
9597
packageName: string,
9698
packageManager: PluginManager,
97-
): Promise<ConfigMeta> {
99+
): Promise<ConfigMeta | undefined> {
98100
if (['javascript', 'typescript'].includes(packageName)) {
99101
throw new Error(`'${packageName}' is ignored as a remote package.`);
100102
}

packages/validator/src/index.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ describe('validator', () => {
134134
);
135135
});
136136

137+
it('should error if config file is not found', async () => {
138+
const filePath = 'path/to/';
139+
140+
(fetchConfig as jest.Mock).mockResolvedValue(undefined);
141+
142+
await expect(isValidConfigAtPath(filePath)).rejects.toThrowError(
143+
`Unable to locate config file at path: ${filePath}`,
144+
);
145+
});
146+
137147
it('should error if config contains multiple invalid properties', async () => {
138148
(fetchConfig as jest.Mock).mockResolvedValue({
139149
location: 'path/to/hypermod.config.js',

packages/validator/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ export function isValidConfig(config: CodeshiftConfig) {
3838
}
3939

4040
export async function isValidConfigAtPath(filePath: string) {
41-
const { config } = await fetchConfig(filePath);
41+
const configMeta = await fetchConfig(filePath);
4242

43-
if (!config) {
43+
if (!configMeta) {
4444
throw new Error(`Unable to locate config file at path: ${filePath}`);
4545
}
4646

47-
const invalidProperites = getInvalidProperties(config);
47+
const invalidProperites = getInvalidProperties(configMeta.config);
4848
if (invalidProperites.length) {
4949
throw new Error(
5050
`Invalid transform ids found: ${invalidProperites.join(', ')}`,
5151
);
5252
}
5353

54-
if (!hasValidTransforms(config)) {
54+
if (!hasValidTransforms(configMeta.config)) {
5555
throw new Error(`Invalid transform ids found for config at "${filePath}".
5656
Please make sure all transforms are identified by a valid semver version. ie 10.0.0`);
5757
}
5858

59-
if (!hasValidPresets(config)) {
59+
if (!hasValidPresets(configMeta.config)) {
6060
throw new Error(`Invalid preset ids found for config at "${filePath}".
6161
Please make sure all presets are kebab case and contain no spaces or special characters. ie sort-imports-by-scope`);
6262
}

0 commit comments

Comments
 (0)