Skip to content

Commit fe48159

Browse files
committed
2.0.0-alpha.2 release
2 parents 67219d7 + a5480b1 commit fe48159

17 files changed

+2921
-881
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
The following is a curated list of changes in the Enact eslint plugin:
44

5+
## [2.0.0-alpha.2] - (February 20, 2025)
6+
7+
* Updated Enact ESLint config to v9 including eslint related modules.
8+
59
## [2.0.0-alpha.1] - (December 6, 2024)
610

711
* Fixed a deprecation warning regarding nodejs.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ With ESLint 2.x.x+:
6666
}
6767
```
6868

69-
Finally, enable all of the rules that you would like to use:
69+
Finally, enable all the rules that you would like to use:
7070

7171
```json
7272
"rules": {
@@ -79,7 +79,7 @@ Finally, enable all of the rules that you would like to use:
7979

8080
# List of supported rules
8181

82-
* [enact/kind-name](docs/rules/kind-name.md): Prevent missing `name` in a Enact component definition
82+
* [enact/kind-name](docs/rules/kind-name.md): Prevent missing `name` in an Enact component definition
8383
* [enact/display-name](docs/rules/display-name.md): Prevent missing `displayName` in a React component definitions without false-flagging Enact kinds
8484
* [enact/prop-types](docs/rules/prop-types.md): Prevent missing props validation in a React component definition
8585
* [enact/no-module-exports-import](docs/rules/no-module-exports-import.md): Disallow module.exports with import statements (see [webpack issue #4039](https://github.com/webpack/webpack/issues/4039))

docs/rules/display-name.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ See [display-name at eslint-plugin-react](https://github.com/yannickcr/eslint-pl
4141

4242
For this rule to work we need to detect React components, this could be very hard since components could be declared in a lot of ways.
4343

44-
For now we should detect components created with:
44+
For now, we should detect components created with:
4545

4646
* `createReactClass()`
4747
* an ES6 class that inherit from `React.Component` or `Component`

docs/rules/prop-types.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Hello = kind({
5959
name: 'Example',
6060
propTypes: {
6161
firstname: React.PropTypes.string.isRequired,
62-
middlename: React.PropTypes.string.isRequired
62+
middlename: React.PropTypes.string.isRequired,
6363
lastname: React.PropTypes.string.isRequired
6464
},
6565
render: function ({firstname, ...rest}) {

index.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ module.exports = {
2525
rules: exportedRules,
2626
configs: {
2727
recommended: {
28-
parserOptions: {
29-
ecmaFeatures: {
30-
jsx: true
28+
languageOptions: {
29+
parserOptions: {
30+
ecmaFeatures: {
31+
jsx: true
32+
}
3133
}
3234
},
3335
rules: {
3436
'enact/prop-types': 2,
3537
'enact/kind-name': 2,
3638
'enact/display-name': 2,
3739
'enact/no-module-exports-import': 1
38-
},
40+
}
3941
},
4042
all: {
41-
parserOptions: {
42-
ecmaFeatures: {
43-
jsx: true
43+
languageOptions: {
44+
parserOptions: {
45+
ecmaFeatures: {
46+
jsx: true
47+
}
4448
}
4549
},
4650
rules: allRules

lib/rules/display-name.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ module.exports = {
9090
}
9191

9292
/**
93-
* Checks if the component have a name set by the transpiler
93+
* Checks if the component has a name set by the transpiler
9494
* @param {ASTNode} node The AST node being checked.
95-
* @returns {Boolean} True ifcomponent have a name, false if not.
95+
* @returns {Boolean} True if component has a name, false if not.
9696
*/
9797
function hasTranspilerName(node) {
9898
var namedObjectAssignment = (

lib/rules/kind-name.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Prevent missing name string property in a Enact kind component definition
2+
* Prevent missing name string property in an Enact kind component definition
33
*
44
* Based on the React display-name rule created by Yannick Croissant
55
* https://github.com/yannickcr/eslint-plugin-react
@@ -96,7 +96,7 @@ module.exports = {
9696
/**
9797
* Checks if the component have a name set by the transpiler
9898
* @param {ASTNode} node The AST node being checked.
99-
* @returns {Boolean} True ifcomponent have a name, false if not.
99+
* @returns {Boolean} True if component have a name, false if not.
100100
*/
101101
function hasTranspilerName(node) {
102102
var namedObjectAssignment = (

lib/rules/no-module-exports-import.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
var {minimatch} = require('minimatch');
11-
var path = require('path');
1211

1312
module.exports = {
1413
meta: {
@@ -31,7 +30,7 @@ module.exports = {
3130
var options = context.options[0] || {};
3231

3332
return {
34-
ImportDeclaration: function ImportDeclaration(node) {
33+
ImportDeclaration: function ImportDeclaration() {
3534
usesES6Imports = true;
3635
},
3736
MemberExpression: function MemberExpression(node) {

lib/rules/prop-types.js

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Prevent missing props validation in a Enact kind component definition
2+
* Prevent missing props validation in an Enact kind component definition
33
*
44
* Based on the React prop-type rule created by Yannick Croissant
55
* https://github.com/yannickcr/eslint-plugin-react
@@ -69,8 +69,8 @@ module.exports = {
6969

7070
/**
7171
* Helper for accessing the current scope in the stack.
72-
* @param {string} key The name of the identifier to access. If omitted, returns the full scope.
73-
* @param {ASTNode} value If provided sets the new value for the identifier.
72+
* @param {string} [key] The name of the identifier to access. If omitted, returns the full scope.
73+
* @param {ASTNode} [value] If provided sets the new value for the identifier.
7474
* @returns {Object|ASTNode} Either the whole scope or the ASTNode associated with the given identifier.
7575
*/
7676
function typeScope(key, value) {
@@ -90,7 +90,7 @@ module.exports = {
9090
*/
9191
function isPropTypesUsage(node) {
9292
var isClassUsage = (
93-
(utils.getParentES6Component() || utils.getParentES5Component()) &&
93+
(utils.getParentES6Component(node) || utils.getParentES5Component(node)) &&
9494
node.object.type === 'ThisExpression' && node.property.name === 'props'
9595
);
9696
var isStatelessFunctionUsage = node.object.name === 'props';
@@ -104,7 +104,7 @@ module.exports = {
104104
*/
105105
function isAnnotatedClassPropsDeclaration(node) {
106106
if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
107-
var tokens = context.getFirstTokens(node, 2);
107+
let tokens = sourceCode.getFirstTokens ? sourceCode.getFirstTokens(node, 2) : context.getFirstTokens(node, 2);
108108
if (
109109
node.typeAnnotation && (
110110
tokens[0].value === 'props' ||
@@ -124,7 +124,7 @@ module.exports = {
124124
*/
125125
function isAnnotatedFunctionPropsDeclaration(node) {
126126
if (node && node.params && node.params.length) {
127-
var tokens = context.getFirstTokens(node.params[0], 2);
127+
let tokens = sourceCode.getFirstTokens ? sourceCode.getFirstTokens(node.params[0], 2) : context.getFirstTokens(node.params[0], 2);
128128
var isAnnotated = node.params[0].typeAnnotation;
129129
var isDestructuredProps = node.params[0].type === 'ObjectPattern';
130130
var isProps = tokens[0].value === 'props' || (tokens[1] && tokens[1].value === 'props');
@@ -170,7 +170,7 @@ module.exports = {
170170
// Special case for class properties
171171
// (babel-eslint does not expose property name so we have to rely on tokens)
172172
if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) {
173-
var tokens = context.getFirstTokens(node, 2);
173+
let tokens = sourceCode.getFirstTokens ? sourceCode.getFirstTokens(node, 2) : context.getFirstTokens(node, 2);
174174
if (
175175
tokens[0].value === 'propTypes' ||
176176
(tokens[1] && tokens[1].value === 'propTypes')
@@ -257,7 +257,7 @@ module.exports = {
257257
// this is the last key, accept everything
258258
return true;
259259
}
260-
// non trivial, check all of them
260+
// non-trivial, check all of them
261261
var unionTypes = propType.children;
262262
var unionPropType = {};
263263
for (var k = 0, z = unionTypes.length; k < z; k++) {
@@ -312,12 +312,12 @@ module.exports = {
312312

313313
/**
314314
* Retrieve the name of a key node
315-
* @param {ASTNode} node The AST node with the key.
315+
* @param {Object|ASTNode} node The AST node with the key.
316316
* @return {string} the name of the key
317317
*/
318318
function getKeyValue(node) {
319319
if (node.type === 'ObjectTypeProperty') {
320-
var tokens = context.getFirstTokens(node, 1);
320+
let tokens = sourceCode.getFirstTokens ? sourceCode.getFirstTokens(node, 1) : context.getFirstTokens(node, 1);
321321
return tokens[0].value;
322322
}
323323
var key = node.key || node.argument || node.property;
@@ -451,7 +451,7 @@ module.exports = {
451451
/**
452452
* Creates the representation of the React props type annotation for the component.
453453
* The representation is used to verify nested used properties.
454-
* @param {ASTNode} annotation Type annotation for the props class property.
454+
* @param {Object|ASTNode} annotation Type annotation for the props class property.
455455
* @return {Object|Boolean} The representation of the declaration, true means
456456
* the property is declared without the need for further analysis.
457457
*/
@@ -511,8 +511,8 @@ module.exports = {
511511
* Check if we are in a class constructor
512512
* @return {boolean} true if we are in a class constructor, false if not
513513
*/
514-
function inConstructor() {
515-
var scope = context.getScope();
514+
function inConstructor(node) {
515+
let scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
516516
while (scope) {
517517
if (scope.block && scope.block.parent && scope.block.parent.kind === 'constructor') {
518518
return true;
@@ -529,7 +529,7 @@ module.exports = {
529529
*/
530530
function getPropertyName(node) {
531531
var isDirectProp = DIRECT_PROPS_REGEX.test(sourceCode.getText(node));
532-
var isInClassComponent = utils.getParentES6Component() || utils.getParentES5Component();
532+
var isInClassComponent = utils.getParentES6Component(node) || utils.getParentES5Component(node);
533533
var isNotInConstructor = !inConstructor(node);
534534

535535
if (isInClassComponent && utils.isKindComponent(isInClassComponent)) {
@@ -576,7 +576,7 @@ module.exports = {
576576
* @param {ASTNode} node The AST node being marked.
577577
*/
578578
function markComputedPropTypes(node) {
579-
var component = components.get(utils.getParentComponent());
579+
var component = components.get(utils.getParentComponent(node));
580580
var computed = component && component.computedProps || [];
581581
for(var i=0; i<node.properties.length; i++) {
582582
if(node.properties[i] && node.properties[i].key && node.properties[i].key.name) {
@@ -593,7 +593,7 @@ module.exports = {
593593
* @param {ASTNode} node The AST node being marked.
594594
*/
595595
function markHandlersPropTypes(node) {
596-
var component = components.get(utils.getParentComponent());
596+
var component = components.get(utils.getParentComponent(node));
597597
var handlers = component && component.handlersProps || [];
598598
for(var i=0; i<node.properties.length; i++) {
599599
if(node.properties[i] && node.properties[i].key && node.properties[i].key.name) {
@@ -608,6 +608,7 @@ module.exports = {
608608
/**
609609
* Mark a prop type as used
610610
* @param {ASTNode} node The AST node being marked.
611+
* @param {Array} [parentNames] The list of parent names.
611612
*/
612613
function markPropTypesAsUsed(node, parentNames) {
613614
parentNames = parentNames || [];
@@ -692,7 +693,7 @@ module.exports = {
692693
// let {firstname} = props
693694
var directDestructuring =
694695
node.init.name === 'props' &&
695-
(utils.getParentStatelessComponent() || inConstructor())
696+
(utils.getParentStatelessComponent(node) || inConstructor(node))
696697
;
697698

698699
if (thisDestructuring) {
@@ -710,7 +711,7 @@ module.exports = {
710711
throw new Error(node.type + ' ASTNodes are not handled by markPropTypesAsUsed');
711712
}
712713

713-
var component = components.get(utils.getParentComponent());
714+
var component = components.get(utils.getParentComponent(node));
714715
var usedPropTypes = component && component.usedPropTypes || [];
715716

716717
switch (type) {
@@ -764,7 +765,7 @@ module.exports = {
764765
/**
765766
* Mark a prop type as declared
766767
* @param {ASTNode} node The AST node being checked.
767-
* @param {propTypes} node The AST node containing the proptypes
768+
* @param {Object|ASTNode} propTypes The AST node containing the proptypes.
768769
*/
769770
function markPropTypesAsDeclared(node, propTypes) {
770771
var componentNode = node;
@@ -819,7 +820,7 @@ module.exports = {
819820
}
820821
break;
821822
case 'Identifier':
822-
var variablesInScope = variable.variablesInScope(context);
823+
var variablesInScope = variable.variablesInScope(sourceCode, context, componentNode)
823824
for (var i = 0, j = variablesInScope.length; i < j; i++) {
824825
if (variablesInScope[i].name !== propTypes.name) {
825826
continue;
@@ -845,7 +846,7 @@ module.exports = {
845846

846847
/**
847848
* Reports undeclared proptypes for a given component
848-
* handlers can be used in computed, but not vice-versa.
849+
* handlers can be used in computed, but not vice versa.
849850
* handlers and computed props can't reference others declared
850851
* only in the same place.
851852
* @param {Object} component The component to process
@@ -889,7 +890,7 @@ module.exports = {
889890
* This method also resolves type aliases where possible.
890891
*
891892
* @param {ASTNode} node The annotation or a node containing the type annotation.
892-
* @returns {ASTNode} The resolved type annotation for the node.
893+
* @returns {Object|ASTNode} The resolved type annotation for the node.
893894
*/
894895
function resolveTypeAnnotation(node) {
895896
var annotation = node.typeAnnotation || node;
@@ -999,7 +1000,7 @@ module.exports = {
9991000
var directDestructuring =
10001001
destructuring &&
10011002
node.init.name === 'props' &&
1002-
(utils.getParentStatelessComponent() || inConstructor())
1003+
(utils.getParentStatelessComponent(node) || inConstructor(node))
10031004
;
10041005

10051006
if (!thisDestructuring && !directDestructuring) {

0 commit comments

Comments
 (0)