-
Notifications
You must be signed in to change notification settings - Fork 21
feat(KEY_CODES): warn about KEY_CODES removal #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d9778d1
39f1b97
f394f16
151525e
2136162
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,12 +62,13 @@ const rules = { | |
"tooltip-remove-props": require('./lib/rules/v5/tooltip-remove-props'), | ||
"remove-removeFindDomNode": require('./lib/rules/v5/remove-removeFindDomNode'), | ||
"popover-remove-props": require('./lib/rules/v5/popover-remove-props'), | ||
"warn-key-codes-removed": require('./lib/rules/v5/warn-key-codes-removed'), | ||
}; | ||
|
||
module.exports = { | ||
configs: { | ||
recommended: { | ||
plugins: ["pf-codemods"], | ||
plugins: ["@patternfly/pf-codemods"], | ||
env: { | ||
browser: true, | ||
node: true, | ||
|
@@ -83,7 +84,8 @@ module.exports = { | |
}, | ||
}, | ||
rules: Object.keys(rules).reduce((acc, rule) => { | ||
acc[`pf-codemods/${rule}`] = "error"; | ||
const severity = rule.includes('warn') ? 'warn' : 'error'; | ||
acc[`@patternfly/pf-codemods/${rule}`] = severity; | ||
|
||
return acc; | ||
}, {}), | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { getPackageImports } = require("../../helpers"); | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/8174 | ||
module.exports = { | ||
meta: { fixable: "code" }, | ||
|
||
create: function (context) { | ||
const imports = getPackageImports(context, "@patternfly/react-core").filter( | ||
(specifier) => specifier.imported.name === "KEY_CODES" | ||
); | ||
|
||
return imports.length == 0 | ||
? {} | ||
: { | ||
ImportDeclaration(node) { | ||
context.report({ | ||
node, | ||
message: | ||
"The KEY_CODES constant has been removed. We suggest refactoring to use the KeyTypes constant instead.", | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const ruleTester = require("../../ruletester"); | ||
const rule = require("../../../lib/rules/v5/warn-key-codes-removed"); | ||
|
||
ruleTester.run("warn-key-codes-removed", rule, { | ||
valid: [ | ||
{ | ||
// No @patternfly/react-core import | ||
code: `KEY_CODES`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { KEY_CODES } from '@patternfly/react-core';`, | ||
output: `import { KEY_CODES } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The KEY_CODES constant has been removed. We suggest refactoring to use the KeyTypes constant instead.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/env node | ||
const fspath = require('path'); | ||
const { CLIEngine } = require('eslint/lib/cli-engine'); | ||
const { configs } = require('eslint-plugin-pf-codemods'); | ||
const { configs } = require('@patternfly/eslint-plugin-pf-codemods'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another fix for the move to the |
||
const { Command } = require('commander'); | ||
const program = new Command(); | ||
|
||
|
@@ -34,9 +34,6 @@ function printResults(engine, results, format) { | |
return false; | ||
} | ||
|
||
// Don't show warnings | ||
results.forEach(result => result.messages = result.messages.filter(message => message.severity === 2)); | ||
|
||
Comment on lines
-37
to
-39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setting was making it so that warnings never surfaced before, it has to be removed so that we can issue them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you think of a reason this was here in the first place? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not off the top of my head, and it was just added in this commit that changed things all over the repo 1ab03a0#diff-06072659dcb0ba81f72d49d18cc77c030ba13d5edacde533742c0dd8ac81730f |
||
const output = formatter(results, { | ||
get rulesMeta() { | ||
if (!rulesMeta) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes an error introduced when we scoped the packages under
@patternfly