Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const runtimeChecks = `runtimeChecks: { strictStateImmutability: true, strictActionImmutability: true }`;
// covers StoreModule.forRoot(ROOT_REDUCERS)
if (node.arguments.length === 1) {
changes.push(new schematics_core_1.InsertChange(sourceFile.fileName, node.arguments[0].getEnd(), `, { ${runtimeChecks}}`));
}
else if (node.arguments.length === 2) {
const storeConfig = node.arguments[1];
if (ts.isObjectLiteralExpression(storeConfig)) {
// covers StoreModule.forRoot(ROOT_REDUCERS, {})
if (storeConfig.properties.length === 0) {
changes.push(new schematics_core_1.InsertChange(sourceFile.fileName, storeConfig.getEnd() - 1, `${runtimeChecks} `));
}
else {
// covers StoreModule.forRoot(ROOT_REDUCERS, { metaReducers })
const lastProperty = storeConfig.properties[storeConfig.properties.length - 1];
changes.push(new schematics_core_1.InsertChange(sourceFile.fileName, lastProperty.getEnd(), `, ${runtimeChecks}`));
}
}
}
}
}
// covers StoreModule.forRoot(ROOT_REDUCERS)
if (node.arguments.length === 1) {
changes.push(
new InsertChange(
sourceFile.fileName,
node.arguments[0].getEnd(),
`, { ${runtimeChecks}}`
)
);
} else if (node.arguments.length === 2) {
const storeConfig = node.arguments[1];
if (ts.isObjectLiteralExpression(storeConfig)) {
// covers StoreModule.forRoot(ROOT_REDUCERS, {})
if (storeConfig.properties.length === 0) {
changes.push(
new InsertChange(
sourceFile.fileName,
storeConfig.getEnd() - 1,
`${runtimeChecks} `
)
);
} else {
// covers StoreModule.forRoot(ROOT_REDUCERS, { metaReducers })
const lastProperty =
storeConfig.properties[storeConfig.properties.length - 1];
changes.push(
new InsertChange(
sourceFile.fileName,
lastProperty.getEnd(),
`, ${runtimeChecks}`
)
if (!(ts.isPropertyAccessExpression(expression) &&
expression.expression.getText(sourceFile) === 'StoreModule' &&
expression.name.getText(sourceFile) === 'forRoot')) {
return;
}
const runtimeChecks = `runtimeChecks: { strictStateImmutability: true, strictActionImmutability: true }`;
// covers StoreModule.forRoot(ROOT_REDUCERS)
if (node.arguments.length === 1) {
changes.push(new schematics_core_1.InsertChange(sourceFile.fileName, node.arguments[0].getEnd(), `, { ${runtimeChecks}}`));
}
else if (node.arguments.length === 2) {
const storeConfig = node.arguments[1];
if (ts.isObjectLiteralExpression(storeConfig)) {
// covers StoreModule.forRoot(ROOT_REDUCERS, {})
if (storeConfig.properties.length === 0) {
changes.push(new schematics_core_1.InsertChange(sourceFile.fileName, storeConfig.getEnd() - 1, `${runtimeChecks} `));
}
else {
// covers StoreModule.forRoot(ROOT_REDUCERS, { metaReducers })
const lastProperty = storeConfig.properties[storeConfig.properties.length - 1];
changes.push(new schematics_core_1.InsertChange(sourceFile.fileName, lastProperty.getEnd(), `, ${runtimeChecks}`));
}
}
}
}
}
// covers StoreModule.forRoot(ROOT_REDUCERS, {})
if (storeConfig.properties.length === 0) {
changes.push(
new InsertChange(
sourceFile.fileName,
storeConfig.getEnd() - 1,
`${runtimeChecks} `
)
);
} else {
// covers StoreModule.forRoot(ROOT_REDUCERS, { metaReducers })
const lastProperty =
storeConfig.properties[storeConfig.properties.length - 1];
changes.push(
new InsertChange(
sourceFile.fileName,
lastProperty.getEnd(),
`, ${runtimeChecks}`
)
);
}
}
}
}
}
const elements = node.elements.map(elem => elem.getText(sourceFile));
const elementsWithoutStoreFreeze = elements.filter(
elemText => elemText !== 'storeFreeze'
);
if (elements.length !== elementsWithoutStoreFreeze.length) {
changes.push(
new RemoveChange(
sourceFile.fileName,
node.getStart(sourceFile),
node.getEnd()
)
);
changes.push(
new InsertChange(
sourceFile.fileName,
node.getStart(sourceFile),
`[${elementsWithoutStoreFreeze.join(', ')}]`
)
);
}
}
}
function crawl(node) {
ts.forEachChild(node, crawl);
if (!ts.isArrayLiteralExpression(node))
return;
const elements = node.elements.map(elem => elem.getText(sourceFile));
const elementsWithoutStoreFreeze = elements.filter(elemText => elemText !== 'storeFreeze');
if (elements.length !== elementsWithoutStoreFreeze.length) {
changes.push(new schematics_core_1.RemoveChange(sourceFile.fileName, node.getStart(sourceFile), node.getEnd()));
changes.push(new schematics_core_1.InsertChange(sourceFile.fileName, node.getStart(sourceFile), `[${elementsWithoutStoreFreeze.join(', ')}]`));
}
}
}