Skip to content

Commit ef6b938

Browse files
committed
Clean up FIXMEs
1 parent 7002551 commit ef6b938

8 files changed

Lines changed: 53 additions & 24 deletions

File tree

transforms/helpers/decorator-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function withDecorators<T>(to: T, decorators: Decorator[] = []): T {
1414

1515
type CallExpressionArg = Parameters<JSCodeshift['callExpression']>[1][number];
1616

17-
/** FIXME: Document */
17+
/** Creates a decorator for a class. */
1818
export function createClassDecorator(
1919
j: JSCodeshift,
2020
classDecoratorProp: EOClassDecoratorProp

transforms/helpers/eo-prop/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export interface EOProps {
3434
instanceProps: EOProp[];
3535
}
3636

37-
/** FIXME */
37+
/**
38+
* Makes an object representing an Ember Object property for the given
39+
* Property, RuntimeData, and ImportPropDecoratorMap.
40+
*/
3841
export default function makeEOProp(
3942
eoProp: Property,
4043
runtimeData: RuntimeData | undefined,

transforms/helpers/import-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export function getImportedDecoratedProps(
324324
for (const specifier of specifiers) {
325325
if (isSpecifierDecorator(specifier, importPropDecoratorMap)) {
326326
const localName = specifier.local?.name;
327-
assert(localName, 'expected localName'); // FIXME: Do we hit this?
327+
assert(localName, 'expected localName');
328328
importedDecorators[localName] = getDecoratorInfo(
329329
specifier,
330330
importPropDecoratorMap

transforms/helpers/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Options {
99
classicDecorator: boolean;
1010
/** Whether to use double or single quotes by default for new statements that are added during the codemod. */
1111
quote: 'single' | 'double';
12-
quotes?: 'single' | 'double'; // FIXME: Why both singular and plural?
12+
quotes?: 'single' | 'double';
1313
/** Apply transformation to only passed type. */
1414
type?: 'services' | 'routes' | 'components' | 'controllers';
1515
/** @private */

transforms/helpers/parse-helper.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import {
2020
getImportedDecoratedProps,
2121
} from './import-helper';
2222
import logger from './log-helper';
23+
import type { Options } from './options';
2324
import { DEFAULT_OPTIONS } from './options';
2425
import type { RuntimeData } from './runtime-data';
26+
import { isRuntimeData } from './runtime-data';
2527
import { createClass, withComments } from './transform-helper';
2628
import { capitalizeFirstLetter, dig, startsWithUpperCaseLetter } from './util';
2729
import {
@@ -274,10 +276,7 @@ export function replaceEmberObjectExpressions(
274276
): boolean | undefined {
275277
options.runtimeData = verified(
276278
getTelemetryFor(path.resolve(filePath)),
277-
// FIXME: move to runtime-data.ts
278-
function isRuntimeData(v: unknown): v is RuntimeData | undefined {
279-
return v === undefined || isRecord(v);
280-
}
279+
isRuntimeData
281280
);
282281

283282
if (!options.runtimeData) {
@@ -303,6 +302,40 @@ export function replaceEmberObjectExpressions(
303302
let transformed = false;
304303
let decoratorsToImportMap: Partial<DecoratorsToImportMap> = {};
305304

305+
({ transformed, decoratorsToImportMap } = transform(
306+
j,
307+
root,
308+
importedDecoratedProps,
309+
options,
310+
filePath,
311+
transformed,
312+
decoratorsToImportMap
313+
));
314+
315+
// Need to find another way, as there might be a case where
316+
// one object from a file is transformed and other is not
317+
if (transformed) {
318+
const decoratorsToImport = Object.keys(decoratorsToImportMap).filter(
319+
(key) => decoratorsToImportMap[key as keyof DecoratorsToImportMap]
320+
);
321+
createDecoratorImportDeclarations(j, root, decoratorsToImport, options);
322+
logger.info(`[${filePath}]: SUCCESS`);
323+
}
324+
return transformed;
325+
}
326+
327+
function transform(
328+
j: JSCodeshift,
329+
root: Collection<unknown>,
330+
importedDecoratedProps: ImportPropDecoratorMap,
331+
options: Options,
332+
filePath: string,
333+
transformed: boolean,
334+
decoratorsToImportMap: Partial<DecoratorsToImportMap>
335+
): {
336+
transformed: boolean;
337+
decoratorsToImportMap: Partial<DecoratorsToImportMap>;
338+
} {
306339
// eslint-disable-next-line unicorn/no-array-for-each
307340
getEmberObjectCallExpressions(j, root).forEach((eoCallExpression) => {
308341
const { eoExpression, mixins } =
@@ -373,16 +406,5 @@ export function replaceEmberObjectExpressions(
373406
);
374407
});
375408

376-
// Need to find another way, as there might be a case where
377-
// one object from a file is transformed and other is not
378-
// FIXME: Is this always falsy?
379-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
380-
if (transformed) {
381-
const decoratorsToImport = Object.keys(decoratorsToImportMap).filter(
382-
(key) => decoratorsToImportMap[key as keyof DecoratorsToImportMap]
383-
);
384-
createDecoratorImportDeclarations(j, root, decoratorsToImport, options);
385-
logger.info(`[${filePath}]: SUCCESS`);
386-
}
387-
return transformed;
409+
return { transformed, decoratorsToImportMap };
388410
}

transforms/helpers/runtime-data.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isRecord } from './util/types';
2+
13
export interface RuntimeData {
24
type?: string;
35
computedProperties?: string[];
@@ -9,3 +11,8 @@ export interface RuntimeData {
911
Array<string | boolean | number | null>
1012
>;
1113
}
14+
15+
/** Type predicate */
16+
export function isRuntimeData(v: unknown): v is RuntimeData | undefined {
17+
return v === undefined || isRecord(v);
18+
}

transforms/helpers/util/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export function assert(
2525
message = 'Assertion Error'
2626
): asserts condition {
2727
if (!condition) {
28-
// FIXME
29-
// eslint-disable-next-line no-debugger
30-
debugger;
3128
throw new Error(message);
3229
}
3330
}

transforms/helpers/validation-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function isTestFile(file: string): boolean {
3333
*/
3434
export function isFileOfType(file: string, type: Options['type']): boolean {
3535
return (
36-
// FIXME: False positive?
36+
// False positive
3737
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3838
!!type && !!TYPE_PATTERNS[type] && minimatch(file, TYPE_PATTERNS[type])
3939
);

0 commit comments

Comments
 (0)