Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fi
- uses: actions/setup-node@v1
with:
node-version: '18'
node-version: '22'

- name: Enable Corepack
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fi
- uses: actions/setup-node@v1
with:
node-version: '18'
node-version: '22'
- run: corepack enable
- run: corepack prepare yarn@4.5.1 --activate
- uses: actions/cache@v4
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
fi
- uses: actions/setup-node@v1
with:
node-version: '18'
node-version: '22'
- run: corepack enable
- run: corepack prepare yarn@4.5.1 --activate
- uses: actions/cache@v4
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
fi
- uses: actions/setup-node@v1
with:
node-version: '18'
node-version: '22'
- run: corepack enable
- run: corepack prepare yarn@4.5.1 --activate
- uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion packages/class-name-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"colors": "^1.4.0",
"commander": "^5.1.0",
"diff": "^5.1.0",
"glob": "^10.2.6"
"glob": "^14.0.3"
},
"devDependencies": {
"@types/diff": "^5.0.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/css-vars-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"colors": "^1.4.0",
"commander": "^5.1.0",
"diff": "^5.1.0",
"glob": "^10.2.6",
"glob": "^14.0.3",
"inquirer": "^12.3.2"
},
"devDependencies": {
Expand Down
22 changes: 11 additions & 11 deletions packages/eslint-plugin-pf-codemods/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function moveSpecifiers(
messageAfterSpecifierPathChange
) {
return function (context) {
const src = context.getSourceCode();
const src = context.sourceCode;
const { imports: fromPackageImports, exports: fromPackageExports } =
getFromPackage(context, fromPackage, specifiersToMove);

Expand Down Expand Up @@ -308,7 +308,7 @@ function pfPackageMatches(packageName, nodeSrc) {
* @returns {Object} an object containing an array of imports and array of named exports
*/
function getFromPackage(context, packageName, specifierNames = []) {
const astBody = context.getSourceCode().ast.body;
const astBody = context.sourceCode.ast.body;
const getSpecifiers = (nodeType) =>
astBody
.filter((node) => node?.type === nodeType)
Expand Down Expand Up @@ -531,7 +531,7 @@ function renameComponents(
// if no data-codemods && closing tag, rename
const newName = componentMap[nodeName];
const updateTagName = (node) =>
context.getSourceCode().getText(node).replace(nodeName, newName);
context.sourceCode.getText(node).replace(nodeName, newName);
const addDataAttr = (jsxStr) =>
`${jsxStr.slice(0, -1)} data-codemods="true">`;
const newOpeningParentTag = newName.includes("Toolbar")
Expand Down Expand Up @@ -645,7 +645,7 @@ function addCallbackParam(
} else if (propProperties.type === "Identifier") {
const matchingVariable = findVariableDeclaration(
propProperties.name,
context.getSourceCode().getScope(node)
context.sourceCode.getScope(node)
);
const matchingDefinition = matchingVariable?.defs.find(
(def) => def.name?.name === propProperties.name
Expand Down Expand Up @@ -686,7 +686,7 @@ function addCallbackParam(
if (isStateSetter(callee)) {
propProperties.isStateSetter = true;
propProperties.stateType =
matchingDefinition?.node.init.typeParameters?.params[0].typeName?.name;
matchingDefinition?.node.init.typeArguments?.params[0].typeName?.name;
}
}
} else if (propProperties.type === "MemberExpression") {
Expand Down Expand Up @@ -810,14 +810,14 @@ function addCallbackParam(

const newParamsText = `${newParam}, ${params
.filter((p) => p.name !== newParam)
.map((p) => context.getSourceCode().getText(p))
.map((p) => context.sourceCode.getText(p))
.join(", ")}`;

fixes.push(
fixer.replaceText(
propProperties.nodeToReplace,
`(${newParamsText}) => ${context
.getSourceCode()
.sourceCode
.getText(propProperties.nodeToReplace)}(${params
.map((p) => p.name)
.join(", ")})`
Expand All @@ -828,11 +828,11 @@ function addCallbackParam(
const firstParam = params[0];

const replacementParams = `${newParam}, ${context
.getSourceCode()
.sourceCode
.getText(firstParam)}`;

const hasParenthesis =
context.getTokenBefore(firstParam).value === "(";
context.sourceCode.getTokenBefore(firstParam).value === "(";

return fixer.replaceText(
firstParam,
Expand All @@ -846,7 +846,7 @@ function addCallbackParam(
currentUseOfNewParam
) => {
const tokenBeforeCurrentUse =
context.getTokenBefore(currentUseOfNewParam);
context.sourceCode.getTokenBefore(currentUseOfNewParam);
const targetRange = [
tokenBeforeCurrentUse.range[0],
currentUseOfNewParam.range[1],
Expand Down Expand Up @@ -910,7 +910,7 @@ function getAllJSXElements(context) {
}
};

traverse(context.getSourceCode().ast);
traverse(context.sourceCode.ast);

return jsxElements;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
if (imports.map(imp => imp.local.name).includes(node.name.name)) {
const attribute = node.attributes.find(node => node.name?.name === 'action');
if (attribute) {
const attributeValue = context.getSourceCode().getText(attribute.value);
const attributeValue = context.sourceCode.getText(attribute.value);
const isLink = attributeValue.includes('Link');
context.report({
node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
const fixes = [
fixer.remove(node)
];
const nextToken = context.getSourceCode().getTokenAfter(node);
const nextToken = context.sourceCode.getTokenAfter(node);
// Remove trailing ,
if (nextToken && nextToken.value === ',') {
fixes.push(fixer.remove(nextToken));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
);
if (victoryCoreImports.length === 0) {
const lastImportNode = context
.getSourceCode()
.sourceCode
.ast.body.filter((node) => node.type === "ImportDeclaration")
.pop();
const importStatement = `import { VictoryZoomContainer } from 'victory-zoom-container';`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
};
if (hasSingleChipGroupParent) {
const childText = node.children
.map(child => context.getSourceCode().getText(child))
.map(child => context.sourceCode.getText(child))
.join('');
const attributes = node.openingElement.attributes
.map(attr => `${attr.name.name}=${attr.value.raw}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ module.exports = {
const needsDataAttr = ['Toolbar', 'ToolbarGroup', 'ToolbarItem'].includes(toolbarName);
const addDataAttr = jsxStr => `${jsxStr.slice(0, -1)} data-codemods="true">`;
const updateTagName = node => context
.getSourceCode()
.sourceCode
.getText(node)
.replace('DataToolbar', 'Toolbar');
const isOpeningTag = context.getSourceCode().getTokenBefore(node).value !== '/';
const isOpeningTag = context.sourceCode.getTokenBefore(node).value !== '/';
const newOpeningParentTag = needsDataAttr ? addDataAttr(updateTagName(node.parent)) : updateTagName(node.parent);
const newClosingTag = updateTagName(node);
context.report({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
child.openingElement.name.name === dropdownItemIconImport.local.name
);
const childText = dropdownIcons.length === 1 && dropdownIcons[0].children
.map(child => context.getSourceCode().getText(child))
.map(child => context.sourceCode.getText(child))
.join('')
.trim();
const variant = node.openingElement.attributes.find(attr => attr.name && attr.name.name === 'variant');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
let replacementValue = '"default"';

if (attribute.value && attribute.value.type === 'JSXExpressionContainer') { // isValid={cond}
const boolCondition = context.getSourceCode().getText(attribute.value.expression);
const boolCondition = context.sourceCode.getText(attribute.value.expression);
if (boolCondition === 'false') {
replacementValue = '"error"'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {

const variantVal = variantAttr.value.expression && variantAttr.value.expression.object.name === 'NavListVariants'
? `variant="${variantAttr.value.expression.property.name}"`
: context.getSourceCode().getText(variantAttr);
: context.sourceCode.getText(variantAttr);
context.report({
node,
messageId: "removeNavListVariant",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
module.exports = {
meta: { fixable: 'code' },
create: function(context) {
const allTokens = context.getSourceCode().ast.body
const allTokens = context.sourceCode.ast.body
.filter(node => node.type !== 'ImportDeclaration')
.map(node => context.getSourceCode().getTokens(node).map(token => token.value))
.map(node => context.sourceCode.getTokens(node).map(token => token.value))
.reduce((acc, val) => acc.concat(val), []);

return {
Expand All @@ -20,7 +20,7 @@ module.exports = {
message: `unused patternfly import ${spec.local.name}`,
fix(fixer) {
const fixes = [fixer.remove(spec)];
const prevToken = context.getSourceCode().getTokenBefore(spec);
const prevToken = context.sourceCode.getTokenBefore(spec);
if (prevToken && prevToken.value === ',') {
fixes.push(fixer.remove(prevToken));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
fix(fixer) {
if (!headerToolsAttr) {
// comment out
return fixer.replaceText(avatarAttr, `/*TODO: move to PageHeaderTools - ${context.getSourceCode().getText(avatarAttr)}*/`)
return fixer.replaceText(avatarAttr, `/*TODO: move to PageHeaderTools - ${context.sourceCode.getText(avatarAttr)}*/`)
} else {
// move into headerTools if possible
if (
Expand All @@ -47,7 +47,7 @@ module.exports = {
headerToolsAttr.value.expression.openingElement.name.name === 'PageHeaderTools' &&
headerToolsAttr.value.expression.closingElement
) {
const intermediateValue = context.getSourceCode().getText(avatarAttr.value);
const intermediateValue = context.sourceCode.getText(avatarAttr.value);
if (avatarAttr.value.expression && avatarAttr.value.expression.type === 'JSXElement') {
avatarValue = `${intermediateValue.substring(1, intermediateValue.length - 1)}`;
} else {
Expand All @@ -62,7 +62,7 @@ module.exports = {
]
} else {
// well we tried... just comment it out then
return fixer.replaceText(avatarAttr, `/*TODO: move to PageHeaderTools - ${context.getSourceCode().getText(avatarAttr)}*/`)
return fixer.replaceText(avatarAttr, `/*TODO: move to PageHeaderTools - ${context.sourceCode.getText(avatarAttr)}*/`)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
if (imports.map(imp => imp.local.name).includes(node.name.name)) {
const attribute = node.attributes.find(node => node.name && node.name.name === 'variant');
if (attribute) {
const attributeValue = context.getSourceCode().getText(attribute.value);
const attributeValue = context.sourceCode.getText(attribute.value);
if (/left|right/.test(attributeValue))
context.report({
node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
if (progressImports.map(imp => imp.local.name).includes(node.name.name)) {
const progressAttribute = node.attributes.find(node => node.name && node.name.name === 'variant');
if (progressAttribute) {
const progressValueString = context.getSourceCode().getText(progressAttribute.value);
const progressValueString = context.sourceCode.getText(progressAttribute.value);
if (progressValueString.includes('info')) {
context.report({
node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
const importStatement = `import { fontAwesomeLogoFull } from '@fortawesome/free-regular-svg-icons';`
if (imports.length) {
if (fortAwesomeImports.length === 0) {
const lastImportNode = context.getSourceCode().ast.body
const lastImportNode = context.sourceCode.ast.body
.filter(node => node.type === 'ImportDeclaration')
.pop();
context.report({
Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = {
ImportSpecifier(node) {
if (imports.map(imp => imp.local.name).includes(node.local.name)) {

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const previousToken = sourceCode.getTokenBefore(node);
const previousTokenText = sourceCode.getText(previousToken);
const lastNodeToken = sourceCode.getLastToken(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
const attribute = node.attributes.find(node => node.name && node.name.name === 'title');
if (attribute) {
const { value } = attribute;
const valueText = context.getSourceCode().getText(value);
const valueText = context.sourceCode.getText(value);
if (valueText.indexOf('TabTitleText') !== -1 || valueText.indexOf('TabTitleIcon') !== -1) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {

const isCellHeightAutoNode = node.callee.name && node.callee.name === 'cellHeightAuto';
if (isCellHeightAutoNode && cellHeightAutoImport.length) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const previousToken = sourceCode.getTokenBefore(node);
const previousTokenText = sourceCode.getText(previousToken);
const lastNodeToken = sourceCode.getLastToken(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
if (titleImports.map(imp => imp.local.name).includes(node.name.name)) {
const sizeAttribute = node.attributes.find(n => n.name && n.name.name === 'size');;
if (sizeAttribute && !validSizes.includes(sizeAttribute.value.value)) {
const sizeValueString = context.getSourceCode().getText(sizeAttribute.value);
const sizeValueString = context.sourceCode.getText(sizeAttribute.value);
const valueGuess = validSizes.find(val => sizeValueString.includes(val)) || 'md';
context.report({
node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
create: function(context) {
const imports = getFromPackage(context, '@patternfly/react-core')
.imports.filter(specifier => ['Wizard', 'WizardBody', 'WizardToggle'].includes(specifier.imported.name));
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

return imports.length == 0 ? {} : {
JSXOpeningElement(node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
if (accordionImports.map(imp => imp.local.name).includes(node.name.name)) {
const sizeAttribute = node.attributes.find(a => a.name?.name === 'displaySize');;
if (sizeAttribute && sizeAttribute.value.value === "large") {
const sizeValueString = context.getSourceCode().getText(sizeAttribute.value);
const sizeValueString = context.sourceCode.getText(sizeAttribute.value);
const valueGuess = 'lg';
context.report({
node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
(attribute) => attribute.name?.name === "src"
);
const getIdentifierType = (identifier) => {
const currentScope = context.getScope();
const currentScope = context.sourceCode.getScope(node);
const matchingVariable = currentScope.variables.find(
(variable) => variable.name === identifier
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
const importExportMessage =
"The BackgroundImageSrcMap interface has been removed.";
const removeSpecifier = (fixer, context, node, specifier) => {
const tokenAfter = context.getSourceCode().getTokenAfter(specifier);
const tokenAfter = context.sourceCode.getTokenAfter(specifier);

const { range } = specifier;
return node.specifiers.length > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
};
const getNodeContent = (node) => {
return node.children
?.map((child) => context.getSourceCode().getText(child))
?.map((child) => context.sourceCode.getText(child))
.join("");
};
const createReplacementContent = (content, conditionOrLogicExpression) => {
Expand All @@ -47,7 +47,7 @@ module.exports = {
return isCardHeaderMainContent ? content : `actions={${content}}`;
}

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

if (conditionOrLogicExpression.type === "LogicalExpression") {
const logicalExpressionContent = sourceCode.getText(
Expand Down
Loading
Loading