eslint-plugin-react-features 1.2.8 → 1.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/src/index.js +1 -239
- package/src/oxlint.js +1 -3
- package/src/rules/component-api/no-arbitrary-token-class.js +1 -74
- package/src/rules/component-api/no-default-test-id.js +1 -46
- package/src/rules/component-api/no-inline-style.js +1 -57
- package/src/rules/component-api/no-is-prefix-prop.js +1 -59
- package/src/rules/component-api/no-kind-prop-discriminator.js +1 -57
- package/src/rules/component-api/no-raw-color-literal.js +1 -55
- package/src/rules/component-api/no-wrapper-sub-component.js +1 -95
- package/src/rules/component-api/require-data-slot.js +1 -40
- package/src/rules/migration/react-class-to-hooks.js +1 -159
- package/src/rules/performance/no-unnecessary-rerenders.js +1 -185
- package/src/rules/performance/react-no-inline-functions.js +1 -187
- package/src/rules/performance/react-render-optimization.js +1 -256
- package/src/rules/react/checked-requires-onchange-or-readonly.js +1 -68
- package/src/rules/react/default-props-match-prop-types.js +1 -99
- package/src/rules/react/display-name.js +1 -133
- package/src/rules/react/hooks-exhaustive-deps.js +1 -466
- package/src/rules/react/jsx-handler-names.js +1 -50
- package/src/rules/react/jsx-key.js +1 -323
- package/src/rules/react/jsx-max-depth.js +1 -71
- package/src/rules/react/jsx-no-bind.js +1 -55
- package/src/rules/react/jsx-no-duplicate-props.js +1 -66
- package/src/rules/react/jsx-no-literals.js +1 -79
- package/src/rules/react/jsx-no-script-url.js +1 -119
- package/src/rules/react/jsx-no-target-blank.js +1 -163
- package/src/rules/react/no-access-state-in-setstate.js +1 -80
- package/src/rules/react/no-adjacent-inline-elements.js +1 -72
- package/src/rules/react/no-arrow-function-lifecycle.js +1 -57
- package/src/rules/react/no-children-prop.js +1 -54
- package/src/rules/react/no-danger-with-children.js +1 -99
- package/src/rules/react/no-danger.js +1 -43
- package/src/rules/react/no-deprecated.js +1 -130
- package/src/rules/react/no-did-mount-set-state.js +1 -50
- package/src/rules/react/no-did-update-set-state.js +1 -71
- package/src/rules/react/no-direct-mutation-state.js +3 -211
- package/src/rules/react/no-find-dom-node.js +1 -50
- package/src/rules/react/no-invalid-html-attribute.js +1 -80
- package/src/rules/react/no-is-mounted.js +1 -46
- package/src/rules/react/no-multi-comp.js +1 -150
- package/src/rules/react/no-namespace.js +1 -37
- package/src/rules/react/no-object-type-as-default-prop.js +1 -53
- package/src/rules/react/no-redundant-should-component-update.js +1 -50
- package/src/rules/react/no-render-return-value.js +1 -67
- package/src/rules/react/no-set-state.js +1 -45
- package/src/rules/react/no-string-refs.js +1 -61
- package/src/rules/react/no-this-in-sfc.js +1 -55
- package/src/rules/react/no-typos.js +1 -90
- package/src/rules/react/no-unescaped-entities.js +1 -44
- package/src/rules/react/no-unknown-property.js +1 -124
- package/src/rules/react/no-unsafe.js +1 -106
- package/src/rules/react/prefer-es6-class.js +1 -50
- package/src/rules/react/prefer-stateless-function.js +1 -126
- package/src/rules/react/prop-types.js +1 -143
- package/src/rules/react/react-in-jsx-scope.js +1 -86
- package/src/rules/react/require-default-props.js +1 -134
- package/src/rules/react/require-optimization.js +1 -397
- package/src/rules/react/require-render-return.js +1 -79
- package/src/rules/react/required-attributes.js +1 -185
- package/src/rules/react/sort-comp.js +1 -146
- package/src/rules/react/state-in-constructor.js +1 -95
- package/src/rules/react/static-property-placement.js +1 -122
- package/src/rules/react/void-dom-elements-no-children.js +1 -89
- package/src/types/index.js +1 -2
|
@@ -1,124 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnknownProperty = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
const VALID_DOM_PROPERTIES = new Set([
|
|
7
|
-
'accept', 'acceptCharset', 'accessKey', 'action', 'allowFullScreen', 'allowTransparency',
|
|
8
|
-
'alt', 'async', 'autoComplete', 'autoFocus', 'autoPlay', 'capture', 'cellPadding',
|
|
9
|
-
'cellSpacing', 'challenge', 'charSet', 'checked', 'cite', 'classID', 'className',
|
|
10
|
-
'colSpan', 'cols', 'content', 'contentEditable', 'contextMenu', 'controls', 'coords',
|
|
11
|
-
'crossOrigin', 'data', 'dateTime', 'default', 'defer', 'dir', 'disabled', 'download',
|
|
12
|
-
'draggable', 'encType', 'form', 'formAction', 'formEncType', 'formMethod', 'formNoValidate',
|
|
13
|
-
'formTarget', 'frameBorder', 'headers', 'height', 'hidden', 'high', 'href', 'hrefLang',
|
|
14
|
-
'htmlFor', 'httpEquiv', 'icon', 'id', 'inputMode', 'integrity', 'is', 'keyParams',
|
|
15
|
-
'keyType', 'kind', 'label', 'lang', 'list', 'loop', 'low', 'manifest', 'marginHeight',
|
|
16
|
-
'marginWidth', 'max', 'maxLength', 'media', 'mediaGroup', 'method', 'min', 'minLength',
|
|
17
|
-
'multiple', 'muted', 'name', 'noValidate', 'nonce', 'open', 'optimum', 'pattern',
|
|
18
|
-
'placeholder', 'poster', 'preload', 'profile', 'radioGroup', 'readOnly', 'rel',
|
|
19
|
-
'required', 'reversed', 'role', 'rowSpan', 'rows', 'sandbox', 'scope', 'scoped',
|
|
20
|
-
'scrolling', 'seamless', 'selected', 'shape', 'size', 'sizes', 'span', 'spellCheck',
|
|
21
|
-
'src', 'srcDoc', 'srcLang', 'srcSet', 'start', 'step', 'style', 'summary', 'tabIndex',
|
|
22
|
-
'target', 'title', 'type', 'useMap', 'value', 'width', 'wmode', 'wrap',
|
|
23
|
-
'children', 'dangerouslySetInnerHTML', 'key', 'ref', 'suppressContentEditableWarning',
|
|
24
|
-
'suppressHydrationWarning',
|
|
25
|
-
'accentHeight', 'accumulate', 'additive', 'alignmentBaseline', 'allowReorder',
|
|
26
|
-
'alphabetic', 'amplitude', 'arabicForm', 'ascent', 'attributeName', 'attributeType',
|
|
27
|
-
'autoReverse', 'azimuth', 'baseFrequency', 'baselineShift', 'baseProfile', 'bbox',
|
|
28
|
-
'begin', 'bias', 'by', 'calcMode', 'capHeight', 'clip', 'clipPath', 'clipPathUnits',
|
|
29
|
-
'clipRule', 'colorInterpolation', 'colorInterpolationFilters', 'colorProfile',
|
|
30
|
-
'colorRendering', 'contentScriptType', 'contentStyleType', 'cursor', 'cx', 'cy',
|
|
31
|
-
'd', 'decelerate', 'descent', 'diffuseConstant', 'direction', 'display', 'divisor',
|
|
32
|
-
'dominantBaseline', 'dur', 'dx', 'dy', 'edgeMode', 'elevation', 'enableBackground',
|
|
33
|
-
'end', 'exponent', 'externalResourcesRequired', 'fill', 'fillOpacity', 'fillRule',
|
|
34
|
-
'filter', 'filterRes', 'filterUnits', 'floodColor', 'floodOpacity', 'focusable',
|
|
35
|
-
'fontFamily', 'fontSize', 'fontSizeAdjust', 'fontStretch', 'fontStyle', 'fontVariant',
|
|
36
|
-
'fontWeight', 'format', 'from', 'fx', 'fy', 'g1', 'g2', 'glyphName', 'glyphOrientationHorizontal',
|
|
37
|
-
'glyphOrientationVertical', 'glyphRef', 'gradientTransform', 'gradientUnits', 'hanging',
|
|
38
|
-
'horizAdvX', 'horizOriginX', 'ideographic', 'imageRendering', 'in', 'in2', 'intercept',
|
|
39
|
-
'k', 'k1', 'k2', 'k3', 'k4', 'kernelMatrix', 'kernelUnitLength', 'kerning', 'keyPoints',
|
|
40
|
-
'keySplines', 'keyTimes', 'lengthAdjust', 'letterSpacing', 'lightingColor', 'limitingConeAngle',
|
|
41
|
-
'local', 'markerEnd', 'markerHeight', 'markerMid', 'markerStart', 'markerUnits', 'markerWidth',
|
|
42
|
-
'mask', 'maskContentUnits', 'maskUnits', 'mathematical', 'mode', 'numOctaves', 'offset',
|
|
43
|
-
'opacity', 'operator', 'order', 'orient', 'orientation', 'origin', 'overflow', 'overlinePosition',
|
|
44
|
-
'overlineThickness', 'paintOrder', 'panose1', 'pathLength', 'patternContentUnits',
|
|
45
|
-
'patternTransform', 'patternUnits', 'pointerEvents', 'points', 'pointsAtX', 'pointsAtY',
|
|
46
|
-
'pointsAtZ', 'preserveAlpha', 'preserveAspectRatio', 'primitiveUnits', 'r', 'radius',
|
|
47
|
-
'refX', 'refY', 'renderingIntent', 'repeatCount', 'repeatDur', 'requiredExtensions',
|
|
48
|
-
'requiredFeatures', 'restart', 'result', 'rotate', 'rx', 'ry', 'scale', 'seed', 'shapeRendering',
|
|
49
|
-
'slope', 'spacing', 'specularConstant', 'specularExponent', 'speed', 'spreadMethod',
|
|
50
|
-
'startOffset', 'stdDeviation', 'stemh', 'stemv', 'stitchTiles', 'stopColor', 'stopOpacity',
|
|
51
|
-
'strikethroughPosition', 'strikethroughThickness', 'string', 'stroke', 'strokeDasharray',
|
|
52
|
-
'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity',
|
|
53
|
-
'strokeWidth', 'surfaceScale', 'systemLanguage', 'tableValues', 'targetX', 'targetY',
|
|
54
|
-
'textAnchor', 'textDecoration', 'textLength', 'textRendering', 'to', 'transform', 'u1',
|
|
55
|
-
'u2', 'underlinePosition', 'underlineThickness', 'unicode', 'unicodeBidi', 'unicodeRange',
|
|
56
|
-
'unitsPerEm', 'vAlphabetic', 'values', 'vectorEffect', 'version', 'vertAdvY', 'vertOriginX',
|
|
57
|
-
'vertOriginY', 'vHanging', 'vIdeographic', 'viewBox', 'viewTarget', 'visibility', 'vMathematical',
|
|
58
|
-
'widths', 'wordSpacing', 'writingMode', 'x', 'x1', 'x2', 'xChannelSelector', 'xHeight',
|
|
59
|
-
'xlinkActuate', 'xlinkArcrole', 'xlinkHref', 'xlinkRole', 'xlinkShow', 'xlinkTitle',
|
|
60
|
-
'xlinkType', 'xmlBase', 'xmlLang', 'xmlSpace', 'y', 'y1', 'y2', 'yChannelSelector',
|
|
61
|
-
'z', 'zoomAndPan',
|
|
62
|
-
'onAbort', 'onAnimationEnd', 'onAnimationIteration', 'onAnimationStart', 'onAuxClick',
|
|
63
|
-
'onBeforeInput', 'onBlur', 'onCanPlay', 'onCanPlayThrough', 'onChange', 'onClick',
|
|
64
|
-
'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate', 'onContextMenu',
|
|
65
|
-
'onCopy', 'onCut', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit',
|
|
66
|
-
'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onDurationChange', 'onEmptied',
|
|
67
|
-
'onEncrypted', 'onEnded', 'onError', 'onFocus', 'onFocusIn', 'onFocusOut', 'onFormData',
|
|
68
|
-
'onGotPointerCapture', 'onInput', 'onInvalid', 'onKeyDown', 'onKeyPress', 'onKeyUp',
|
|
69
|
-
'onLoad', 'onLoadStart', 'onLoadedData', 'onLoadedMetadata', 'onLostPointerCapture',
|
|
70
|
-
'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver',
|
|
71
|
-
'onMouseUp', 'onPaste', 'onPause', 'onPlay', 'onPlaying', 'onPointerCancel', 'onPointerDown',
|
|
72
|
-
'onPointerEnter', 'onPointerLeave', 'onPointerMove', 'onPointerOut', 'onPointerOver',
|
|
73
|
-
'onPointerUp', 'onProgress', 'onRateChange', 'onReset', 'onResize', 'onScroll', 'onSeeked',
|
|
74
|
-
'onSeeking', 'onSelect', 'onStalled', 'onSubmit', 'onSuspend', 'onTimeUpdate', 'onToggle',
|
|
75
|
-
'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart', 'onTransitionEnd', 'onVolumeChange',
|
|
76
|
-
'onWaiting', 'onWheel',
|
|
77
|
-
]);
|
|
78
|
-
const REACT_PROPS = new Set([
|
|
79
|
-
'defaultChecked', 'defaultValue', 'suppressContentEditableWarning', 'suppressHydrationWarning',
|
|
80
|
-
]);
|
|
81
|
-
exports.noUnknownProperty = (0, eslint_devkit_1.createRule)({
|
|
82
|
-
name: 'no-unknown-property',
|
|
83
|
-
meta: {
|
|
84
|
-
type: 'problem',
|
|
85
|
-
docs: {
|
|
86
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unknown-property.md',
|
|
87
|
-
description: 'Disallow unknown DOM properties',
|
|
88
|
-
},
|
|
89
|
-
schema: [],
|
|
90
|
-
messages: {
|
|
91
|
-
noUnknownProperty: (0, eslint_devkit_2.formatLLMMessage)({
|
|
92
|
-
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
93
|
-
issueName: 'Unknown DOM Property',
|
|
94
|
-
description: 'Unknown DOM property detected',
|
|
95
|
-
severity: 'MEDIUM',
|
|
96
|
-
fix: 'Use standard DOM properties or data attributes (data-*)',
|
|
97
|
-
documentationLink: 'https://react.dev/learn/writing-markup-with-jsx#html-attributes',
|
|
98
|
-
}),
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
defaultOptions: [],
|
|
102
|
-
create(context) {
|
|
103
|
-
return {
|
|
104
|
-
JSXAttribute(node) {
|
|
105
|
-
const elementName = node.parent.name;
|
|
106
|
-
if (elementName.type !== 'JSXIdentifier' || !/^[a-z]/.test(elementName.name)) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (node.name.type === 'JSXIdentifier') {
|
|
110
|
-
const propName = node.name.name;
|
|
111
|
-
if (REACT_PROPS.has(propName) || propName.startsWith('data-') || propName.startsWith('aria-')) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (!VALID_DOM_PROPERTIES.has(propName)) {
|
|
115
|
-
context.report({
|
|
116
|
-
node: node.name,
|
|
117
|
-
messageId: 'noUnknownProperty',
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
},
|
|
124
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnknownProperty=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const VALID_DOM_PROPERTIES=new Set(["accept","acceptCharset","accessKey","action","allowFullScreen","allowTransparency","alt","async","autoComplete","autoFocus","autoPlay","capture","cellPadding","cellSpacing","challenge","charSet","checked","cite","classID","className","colSpan","cols","content","contentEditable","contextMenu","controls","coords","crossOrigin","data","dateTime","default","defer","dir","disabled","download","draggable","encType","form","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","headers","height","hidden","high","href","hrefLang","htmlFor","httpEquiv","icon","id","inputMode","integrity","is","keyParams","keyType","kind","label","lang","list","loop","low","manifest","marginHeight","marginWidth","max","maxLength","media","mediaGroup","method","min","minLength","multiple","muted","name","noValidate","nonce","open","optimum","pattern","placeholder","poster","preload","profile","radioGroup","readOnly","rel","required","reversed","role","rowSpan","rows","sandbox","scope","scoped","scrolling","seamless","selected","shape","size","sizes","span","spellCheck","src","srcDoc","srcLang","srcSet","start","step","style","summary","tabIndex","target","title","type","useMap","value","width","wmode","wrap","children","dangerouslySetInnerHTML","key","ref","suppressContentEditableWarning","suppressHydrationWarning","accentHeight","accumulate","additive","alignmentBaseline","allowReorder","alphabetic","amplitude","arabicForm","ascent","attributeName","attributeType","autoReverse","azimuth","baseFrequency","baselineShift","baseProfile","bbox","begin","bias","by","calcMode","capHeight","clip","clipPath","clipPathUnits","clipRule","colorInterpolation","colorInterpolationFilters","colorProfile","colorRendering","contentScriptType","contentStyleType","cursor","cx","cy","d","decelerate","descent","diffuseConstant","direction","display","divisor","dominantBaseline","dur","dx","dy","edgeMode","elevation","enableBackground","end","exponent","externalResourcesRequired","fill","fillOpacity","fillRule","filter","filterRes","filterUnits","floodColor","floodOpacity","focusable","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontStyle","fontVariant","fontWeight","format","from","fx","fy","g1","g2","glyphName","glyphOrientationHorizontal","glyphOrientationVertical","glyphRef","gradientTransform","gradientUnits","hanging","horizAdvX","horizOriginX","ideographic","imageRendering","in","in2","intercept","k","k1","k2","k3","k4","kernelMatrix","kernelUnitLength","kerning","keyPoints","keySplines","keyTimes","lengthAdjust","letterSpacing","lightingColor","limitingConeAngle","local","markerEnd","markerHeight","markerMid","markerStart","markerUnits","markerWidth","mask","maskContentUnits","maskUnits","mathematical","mode","numOctaves","offset","opacity","operator","order","orient","orientation","origin","overflow","overlinePosition","overlineThickness","paintOrder","panose1","pathLength","patternContentUnits","patternTransform","patternUnits","pointerEvents","points","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","r","radius","refX","refY","renderingIntent","repeatCount","repeatDur","requiredExtensions","requiredFeatures","restart","result","rotate","rx","ry","scale","seed","shapeRendering","slope","spacing","specularConstant","specularExponent","speed","spreadMethod","startOffset","stdDeviation","stemh","stemv","stitchTiles","stopColor","stopOpacity","strikethroughPosition","strikethroughThickness","string","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","surfaceScale","systemLanguage","tableValues","targetX","targetY","textAnchor","textDecoration","textLength","textRendering","to","transform","u1","u2","underlinePosition","underlineThickness","unicode","unicodeBidi","unicodeRange","unitsPerEm","vAlphabetic","values","vectorEffect","version","vertAdvY","vertOriginX","vertOriginY","vHanging","vIdeographic","viewBox","viewTarget","visibility","vMathematical","widths","wordSpacing","writingMode","x","x1","x2","xChannelSelector","xHeight","xlinkActuate","xlinkArcrole","xlinkHref","xlinkRole","xlinkShow","xlinkTitle","xlinkType","xmlBase","xmlLang","xmlSpace","y","y1","y2","yChannelSelector","z","zoomAndPan","onAbort","onAnimationEnd","onAnimationIteration","onAnimationStart","onAuxClick","onBeforeInput","onBlur","onCanPlay","onCanPlayThrough","onChange","onClick","onCompositionEnd","onCompositionStart","onCompositionUpdate","onContextMenu","onCopy","onCut","onDoubleClick","onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onFocus","onFocusIn","onFocusOut","onFormData","onGotPointerCapture","onInput","onInvalid","onKeyDown","onKeyPress","onKeyUp","onLoad","onLoadStart","onLoadedData","onLoadedMetadata","onLostPointerCapture","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onPaste","onPause","onPlay","onPlaying","onPointerCancel","onPointerDown","onPointerEnter","onPointerLeave","onPointerMove","onPointerOut","onPointerOver","onPointerUp","onProgress","onRateChange","onReset","onResize","onScroll","onSeeked","onSeeking","onSelect","onStalled","onSubmit","onSuspend","onTimeUpdate","onToggle","onTouchCancel","onTouchEnd","onTouchMove","onTouchStart","onTransitionEnd","onVolumeChange","onWaiting","onWheel"]);const REACT_PROPS=new Set(["defaultChecked","defaultValue","suppressContentEditableWarning","suppressHydrationWarning"]);exports.noUnknownProperty=(0,eslint_devkit_1.createRule)({name:"no-unknown-property",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unknown-property.md",description:"Disallow unknown DOM properties"},schema:[],messages:{noUnknownProperty:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unknown DOM Property",description:"Unknown DOM property detected",severity:"MEDIUM",fix:"Use standard DOM properties or data attributes (data-*)",documentationLink:"https://react.dev/learn/writing-markup-with-jsx#html-attributes"})}},defaultOptions:[],create(context){return{JSXAttribute(node){const elementName=node.parent.name;if(elementName.type!=="JSXIdentifier"||!/^[a-z]/.test(elementName.name)){return}if(node.name.type==="JSXIdentifier"){const propName=node.name.name;if(REACT_PROPS.has(propName)||propName.startsWith("data-")||propName.startsWith("aria-")){return}if(!VALID_DOM_PROPERTIES.has(propName)){context.report({node:node.name,messageId:"noUnknownProperty"})}}}}}});
|
|
@@ -1,106 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noUnsafe = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
const UNSAFE_METHODS = {
|
|
7
|
-
'UNSAFE_componentWillMount': { replacement: 'componentDidMount or useEffect' },
|
|
8
|
-
'UNSAFE_componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps or useEffect' },
|
|
9
|
-
'UNSAFE_componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate or useEffect' },
|
|
10
|
-
};
|
|
11
|
-
const LEGACY_METHODS = {
|
|
12
|
-
'componentWillMount': { replacement: 'componentDidMount or useEffect' },
|
|
13
|
-
'componentWillReceiveProps': { replacement: 'static getDerivedStateFromProps or useEffect' },
|
|
14
|
-
'componentWillUpdate': { replacement: 'getSnapshotBeforeUpdate or useEffect' },
|
|
15
|
-
};
|
|
16
|
-
exports.noUnsafe = (0, eslint_devkit_2.createRule)({
|
|
17
|
-
name: 'no-unsafe',
|
|
18
|
-
meta: {
|
|
19
|
-
type: 'problem',
|
|
20
|
-
docs: {
|
|
21
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unsafe.md',
|
|
22
|
-
description: 'Prevent usage of unsafe lifecycle methods',
|
|
23
|
-
},
|
|
24
|
-
messages: {
|
|
25
|
-
noUnsafe: (0, eslint_devkit_1.formatLLMMessage)({
|
|
26
|
-
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
27
|
-
issueName: 'Unsafe Lifecycle Method',
|
|
28
|
-
description: '"{{method}}" is unsafe and may cause bugs in concurrent mode',
|
|
29
|
-
severity: 'HIGH',
|
|
30
|
-
fix: 'Use {{replacement}} instead',
|
|
31
|
-
documentationLink: 'https://react.dev/blog/2018/03/27/update-on-async-rendering',
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
schema: [
|
|
35
|
-
{
|
|
36
|
-
type: 'object',
|
|
37
|
-
properties: {
|
|
38
|
-
checkAliases: { type: 'boolean', default: false },
|
|
39
|
-
},
|
|
40
|
-
additionalProperties: false,
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
defaultOptions: [{}],
|
|
45
|
-
create(context, [options = {}]) {
|
|
46
|
-
const { checkAliases = false } = options ?? {};
|
|
47
|
-
let inClassComponent = false;
|
|
48
|
-
function checkMethod(node) {
|
|
49
|
-
if (!inClassComponent)
|
|
50
|
-
return;
|
|
51
|
-
if (node.key.type !== 'Identifier')
|
|
52
|
-
return;
|
|
53
|
-
const methodName = node.key.name;
|
|
54
|
-
const unsafeInfo = UNSAFE_METHODS[methodName];
|
|
55
|
-
if (unsafeInfo) {
|
|
56
|
-
context.report({
|
|
57
|
-
node,
|
|
58
|
-
messageId: 'noUnsafe',
|
|
59
|
-
data: {
|
|
60
|
-
method: methodName,
|
|
61
|
-
replacement: unsafeInfo.replacement,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (checkAliases) {
|
|
67
|
-
const legacyInfo = LEGACY_METHODS[methodName];
|
|
68
|
-
if (legacyInfo) {
|
|
69
|
-
context.report({
|
|
70
|
-
node,
|
|
71
|
-
messageId: 'noUnsafe',
|
|
72
|
-
data: {
|
|
73
|
-
method: methodName,
|
|
74
|
-
replacement: legacyInfo.replacement,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
ClassDeclaration(node) {
|
|
82
|
-
if (!node.superClass)
|
|
83
|
-
return;
|
|
84
|
-
if (node.superClass.type === 'MemberExpression') {
|
|
85
|
-
if (node.superClass.object.type === 'Identifier' &&
|
|
86
|
-
node.superClass.object.name === 'React' &&
|
|
87
|
-
node.superClass.property.type === 'Identifier' &&
|
|
88
|
-
(node.superClass.property.name === 'Component' ||
|
|
89
|
-
node.superClass.property.name === 'PureComponent')) {
|
|
90
|
-
inClassComponent = true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else if (node.superClass.type === 'Identifier') {
|
|
94
|
-
if (node.superClass.name === 'Component' || node.superClass.name === 'PureComponent') {
|
|
95
|
-
inClassComponent = true;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
'ClassDeclaration:exit'() {
|
|
100
|
-
inClassComponent = false;
|
|
101
|
-
},
|
|
102
|
-
MethodDefinition: checkMethod,
|
|
103
|
-
PropertyDefinition: checkMethod,
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnsafe=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const UNSAFE_METHODS={"UNSAFE_componentWillMount":{replacement:"componentDidMount or useEffect"},"UNSAFE_componentWillReceiveProps":{replacement:"static getDerivedStateFromProps or useEffect"},"UNSAFE_componentWillUpdate":{replacement:"getSnapshotBeforeUpdate or useEffect"}};const LEGACY_METHODS={"componentWillMount":{replacement:"componentDidMount or useEffect"},"componentWillReceiveProps":{replacement:"static getDerivedStateFromProps or useEffect"},"componentWillUpdate":{replacement:"getSnapshotBeforeUpdate or useEffect"}};exports.noUnsafe=(0,eslint_devkit_2.createRule)({name:"no-unsafe",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unsafe.md",description:"Prevent usage of unsafe lifecycle methods"},messages:{noUnsafe:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.WARNING,issueName:"Unsafe Lifecycle Method",description:'"{{method}}" is unsafe and may cause bugs in concurrent mode',severity:"HIGH",fix:"Use {{replacement}} instead",documentationLink:"https://react.dev/blog/2018/03/27/update-on-async-rendering"})},schema:[{type:"object",properties:{checkAliases:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{}],create(context,[options={}]){const{checkAliases=false}=options??{};let inClassComponent=false;function checkMethod(node){if(!inClassComponent)return;if(node.key.type!=="Identifier")return;const methodName=node.key.name;const unsafeInfo=UNSAFE_METHODS[methodName];if(unsafeInfo){context.report({node,messageId:"noUnsafe",data:{method:methodName,replacement:unsafeInfo.replacement}});return}if(checkAliases){const legacyInfo=LEGACY_METHODS[methodName];if(legacyInfo){context.report({node,messageId:"noUnsafe",data:{method:methodName,replacement:legacyInfo.replacement}})}}}return{ClassDeclaration(node){if(!node.superClass)return;if(node.superClass.type==="MemberExpression"){if(node.superClass.object.type==="Identifier"&&node.superClass.object.name==="React"&&node.superClass.property.type==="Identifier"&&(node.superClass.property.name==="Component"||node.superClass.property.name==="PureComponent")){inClassComponent=true}}else if(node.superClass.type==="Identifier"){if(node.superClass.name==="Component"||node.superClass.name==="PureComponent"){inClassComponent=true}}},"ClassDeclaration:exit"(){inClassComponent=false},MethodDefinition:checkMethod,PropertyDefinition:checkMethod}}});
|
|
@@ -1,50 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.preferEs6Class = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.preferEs6Class = (0, eslint_devkit_1.createRule)({
|
|
7
|
-
name: 'prefer-es6-class',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'problem',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prefer-es6-class.md',
|
|
12
|
-
description: 'Prefer ES6 classes over createClass',
|
|
13
|
-
},
|
|
14
|
-
schema: [],
|
|
15
|
-
messages: {
|
|
16
|
-
preferEs6Class: (0, eslint_devkit_2.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_2.MessageIcons.MIGRATION,
|
|
18
|
-
issueName: 'Legacy createClass',
|
|
19
|
-
description: 'React.createClass() is deprecated',
|
|
20
|
-
severity: 'HIGH',
|
|
21
|
-
fix: 'Convert to ES6 class component',
|
|
22
|
-
documentationLink: 'https://react.dev/reference/react/createClass',
|
|
23
|
-
}),
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
defaultOptions: [],
|
|
27
|
-
create(context) {
|
|
28
|
-
return {
|
|
29
|
-
CallExpression(node) {
|
|
30
|
-
if (node.callee.type === 'MemberExpression' &&
|
|
31
|
-
node.callee.object.type === 'Identifier' &&
|
|
32
|
-
node.callee.object.name === 'React' &&
|
|
33
|
-
node.callee.property.type === 'Identifier' &&
|
|
34
|
-
node.callee.property.name === 'createClass') {
|
|
35
|
-
context.report({
|
|
36
|
-
node: node.callee.property,
|
|
37
|
-
messageId: 'preferEs6Class',
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (node.callee.type === 'Identifier' &&
|
|
41
|
-
node.callee.name === 'createClass') {
|
|
42
|
-
context.report({
|
|
43
|
-
node: node.callee,
|
|
44
|
-
messageId: 'preferEs6Class',
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.preferEs6Class=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.preferEs6Class=(0,eslint_devkit_1.createRule)({name:"prefer-es6-class",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prefer-es6-class.md",description:"Prefer ES6 classes over createClass"},schema:[],messages:{preferEs6Class:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.MIGRATION,issueName:"Legacy createClass",description:"React.createClass() is deprecated",severity:"HIGH",fix:"Convert to ES6 class component",documentationLink:"https://react.dev/reference/react/createClass"})}},defaultOptions:[],create(context){return{CallExpression(node){if(node.callee.type==="MemberExpression"&&node.callee.object.type==="Identifier"&&node.callee.object.name==="React"&&node.callee.property.type==="Identifier"&&node.callee.property.name==="createClass"){context.report({node:node.callee.property,messageId:"preferEs6Class"})}if(node.callee.type==="Identifier"&&node.callee.name==="createClass"){context.report({node:node.callee,messageId:"preferEs6Class"})}}}}});
|
|
@@ -1,126 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.preferStatelessFunction = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.preferStatelessFunction = (0, eslint_devkit_1.createRule)({
|
|
7
|
-
name: 'prefer-stateless-function',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'problem',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prefer-stateless-function.md',
|
|
12
|
-
description: 'Prefer stateless functions',
|
|
13
|
-
},
|
|
14
|
-
messages: {
|
|
15
|
-
preferStatelessFunction: (0, eslint_devkit_2.formatLLMMessage)({
|
|
16
|
-
icon: eslint_devkit_2.MessageIcons.MIGRATION,
|
|
17
|
-
issueName: 'Class Component',
|
|
18
|
-
description: 'Class component without state or lifecycle methods',
|
|
19
|
-
severity: 'MEDIUM',
|
|
20
|
-
fix: 'Convert to functional component',
|
|
21
|
-
documentationLink: 'https://react.dev/learn/your-first-component',
|
|
22
|
-
}),
|
|
23
|
-
},
|
|
24
|
-
schema: [
|
|
25
|
-
{
|
|
26
|
-
type: 'object',
|
|
27
|
-
properties: {
|
|
28
|
-
ignorePureComponents: {
|
|
29
|
-
type: 'boolean',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
additionalProperties: false,
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
defaultOptions: [{ ignorePureComponents: false }],
|
|
37
|
-
create(context) {
|
|
38
|
-
const [options] = context.options;
|
|
39
|
-
const ignorePureComponents = options?.ignorePureComponents ?? false;
|
|
40
|
-
return {
|
|
41
|
-
ClassDeclaration(node) {
|
|
42
|
-
if (!isReactComponent(node))
|
|
43
|
-
return;
|
|
44
|
-
if (ignorePureComponents && isPureComponent(node))
|
|
45
|
-
return;
|
|
46
|
-
if (!hasState(node) && !hasLifecycleMethods(node)) {
|
|
47
|
-
context.report({
|
|
48
|
-
node: node.id || node,
|
|
49
|
-
messageId: 'preferStatelessFunction',
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
function isReactComponent(node) {
|
|
55
|
-
if (!node.superClass)
|
|
56
|
-
return false;
|
|
57
|
-
if (node.superClass.type === 'Identifier') {
|
|
58
|
-
return node.superClass.name === 'Component' || node.superClass.name === 'PureComponent';
|
|
59
|
-
}
|
|
60
|
-
if (node.superClass.type === 'MemberExpression') {
|
|
61
|
-
return (node.superClass.object.type === 'Identifier' &&
|
|
62
|
-
node.superClass.object.name === 'React' &&
|
|
63
|
-
node.superClass.property.type === 'Identifier' &&
|
|
64
|
-
(node.superClass.property.name === 'Component' || node.superClass.property.name === 'PureComponent'));
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
function isPureComponent(node) {
|
|
69
|
-
if (!node.superClass)
|
|
70
|
-
return false;
|
|
71
|
-
if (node.superClass.type === 'Identifier') {
|
|
72
|
-
return node.superClass.name === 'PureComponent';
|
|
73
|
-
}
|
|
74
|
-
if (node.superClass.type === 'MemberExpression') {
|
|
75
|
-
return (node.superClass.object.type === 'Identifier' &&
|
|
76
|
-
node.superClass.object.name === 'React' &&
|
|
77
|
-
node.superClass.property.type === 'Identifier' &&
|
|
78
|
-
node.superClass.property.name === 'PureComponent');
|
|
79
|
-
}
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
function hasState(node) {
|
|
83
|
-
for (const member of node.body.body) {
|
|
84
|
-
if (member.type === 'PropertyDefinition' &&
|
|
85
|
-
member.key.type === 'Identifier' &&
|
|
86
|
-
member.key.name === 'state') {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
if (member.type === 'MethodDefinition' &&
|
|
90
|
-
member.key.type === 'Identifier' &&
|
|
91
|
-
member.key.name === 'constructor') {
|
|
92
|
-
const body = member.value.body;
|
|
93
|
-
if (!body)
|
|
94
|
-
continue;
|
|
95
|
-
for (const statement of body.body) {
|
|
96
|
-
if (statement.type === 'ExpressionStatement' &&
|
|
97
|
-
statement.expression.type === 'AssignmentExpression' &&
|
|
98
|
-
statement.expression.left.type === 'MemberExpression' &&
|
|
99
|
-
statement.expression.left.object.type === 'ThisExpression' &&
|
|
100
|
-
statement.expression.left.property.type === 'Identifier' &&
|
|
101
|
-
statement.expression.left.property.name === 'state') {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
function hasLifecycleMethods(node) {
|
|
110
|
-
const lifecycleMethods = new Set([
|
|
111
|
-
'componentDidMount', 'componentDidUpdate', 'componentWillUnmount',
|
|
112
|
-
'componentWillMount', 'componentWillReceiveProps', 'componentWillUpdate',
|
|
113
|
-
'shouldComponentUpdate', 'getDerivedStateFromProps', 'getSnapshotBeforeUpdate',
|
|
114
|
-
'UNSAFE_componentWillMount', 'UNSAFE_componentWillReceiveProps', 'UNSAFE_componentWillUpdate',
|
|
115
|
-
]);
|
|
116
|
-
for (const member of node.body.body) {
|
|
117
|
-
if (member.type === 'MethodDefinition' &&
|
|
118
|
-
member.key.type === 'Identifier' &&
|
|
119
|
-
lifecycleMethods.has(member.key.name)) {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.preferStatelessFunction=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.preferStatelessFunction=(0,eslint_devkit_1.createRule)({name:"prefer-stateless-function",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prefer-stateless-function.md",description:"Prefer stateless functions"},messages:{preferStatelessFunction:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.MIGRATION,issueName:"Class Component",description:"Class component without state or lifecycle methods",severity:"MEDIUM",fix:"Convert to functional component",documentationLink:"https://react.dev/learn/your-first-component"})},schema:[{type:"object",properties:{ignorePureComponents:{type:"boolean"}},additionalProperties:false}]},defaultOptions:[{ignorePureComponents:false}],create(context){const[options]=context.options;const ignorePureComponents=options?.ignorePureComponents??false;return{ClassDeclaration(node){if(!isReactComponent(node))return;if(ignorePureComponents&&isPureComponent(node))return;if(!hasState(node)&&!hasLifecycleMethods(node)){context.report({node:node.id||node,messageId:"preferStatelessFunction"})}}};function isReactComponent(node){if(!node.superClass)return false;if(node.superClass.type==="Identifier"){return node.superClass.name==="Component"||node.superClass.name==="PureComponent"}if(node.superClass.type==="MemberExpression"){return node.superClass.object.type==="Identifier"&&node.superClass.object.name==="React"&&node.superClass.property.type==="Identifier"&&(node.superClass.property.name==="Component"||node.superClass.property.name==="PureComponent")}return false}function isPureComponent(node){if(!node.superClass)return false;if(node.superClass.type==="Identifier"){return node.superClass.name==="PureComponent"}if(node.superClass.type==="MemberExpression"){return node.superClass.object.type==="Identifier"&&node.superClass.object.name==="React"&&node.superClass.property.type==="Identifier"&&node.superClass.property.name==="PureComponent"}return false}function hasState(node){for(const member of node.body.body){if(member.type==="PropertyDefinition"&&member.key.type==="Identifier"&&member.key.name==="state"){return true}if(member.type==="MethodDefinition"&&member.key.type==="Identifier"&&member.key.name==="constructor"){const body=member.value.body;if(!body)continue;for(const statement of body.body){if(statement.type==="ExpressionStatement"&&statement.expression.type==="AssignmentExpression"&&statement.expression.left.type==="MemberExpression"&&statement.expression.left.object.type==="ThisExpression"&&statement.expression.left.property.type==="Identifier"&&statement.expression.left.property.name==="state"){return true}}}}return false}function hasLifecycleMethods(node){const lifecycleMethods=new Set(["componentDidMount","componentDidUpdate","componentWillUnmount","componentWillMount","componentWillReceiveProps","componentWillUpdate","shouldComponentUpdate","getDerivedStateFromProps","getSnapshotBeforeUpdate","UNSAFE_componentWillMount","UNSAFE_componentWillReceiveProps","UNSAFE_componentWillUpdate"]);for(const member of node.body.body){if(member.type==="MethodDefinition"&&member.key.type==="Identifier"&&lifecycleMethods.has(member.key.name)){return true}}return false}}});
|
|
@@ -1,143 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propTypes = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.propTypes = (0, eslint_devkit_1.createRule)({
|
|
7
|
-
name: 'prop-types',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'problem',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prop-types.md',
|
|
12
|
-
description: 'Enforce prop types usage',
|
|
13
|
-
},
|
|
14
|
-
schema: [
|
|
15
|
-
{
|
|
16
|
-
type: 'object',
|
|
17
|
-
properties: {
|
|
18
|
-
ignore: {
|
|
19
|
-
type: 'array',
|
|
20
|
-
items: { type: 'string' },
|
|
21
|
-
},
|
|
22
|
-
customValidators: {
|
|
23
|
-
type: 'array',
|
|
24
|
-
items: { type: 'string' },
|
|
25
|
-
},
|
|
26
|
-
skipUndeclared: {
|
|
27
|
-
type: 'boolean',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
additionalProperties: false,
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
messages: {
|
|
34
|
-
propTypes: (0, eslint_devkit_2.formatLLMMessage)({
|
|
35
|
-
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
36
|
-
issueName: 'Missing PropTypes',
|
|
37
|
-
description: 'Component missing prop type validation',
|
|
38
|
-
severity: 'MEDIUM',
|
|
39
|
-
fix: 'Add propTypes static property or use TypeScript',
|
|
40
|
-
documentationLink: 'https://react.dev/learn/components-and-props#specifying-a-default-prop',
|
|
41
|
-
}),
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
defaultOptions: [{}],
|
|
45
|
-
create(context) {
|
|
46
|
-
const [options] = context.options;
|
|
47
|
-
const ignore = options?.ignore ?? [];
|
|
48
|
-
const skipUndeclared = options?.skipUndeclared ?? false;
|
|
49
|
-
const components = [];
|
|
50
|
-
const propTypesMap = new Map();
|
|
51
|
-
return {
|
|
52
|
-
ClassDeclaration(node) {
|
|
53
|
-
if (isReactComponent(node) && !ignore.includes(node.id?.name || '')) {
|
|
54
|
-
components.push(node);
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
'PropertyDefinition[key.name="propTypes"]'(node) {
|
|
58
|
-
if (node.parent.type === 'ClassBody') {
|
|
59
|
-
const classNode = node.parent.parent;
|
|
60
|
-
if (classNode.id?.name) {
|
|
61
|
-
propTypesMap.set(classNode.id.name, node);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
'Program:exit'() {
|
|
66
|
-
for (const component of components) {
|
|
67
|
-
const componentName = component.id?.name;
|
|
68
|
-
if (!componentName)
|
|
69
|
-
continue;
|
|
70
|
-
const propTypesProp = propTypesMap.get(componentName);
|
|
71
|
-
if (propTypesProp || (skipUndeclared && !hasPropsUsage(component))) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
context.report({
|
|
75
|
-
node: component.id || component,
|
|
76
|
-
messageId: 'propTypes',
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
function isReactComponent(node) {
|
|
82
|
-
if (!node.superClass)
|
|
83
|
-
return false;
|
|
84
|
-
if (node.superClass.type === 'Identifier') {
|
|
85
|
-
return node.superClass.name === 'Component' || node.superClass.name === 'PureComponent';
|
|
86
|
-
}
|
|
87
|
-
if (node.superClass.type === 'MemberExpression') {
|
|
88
|
-
return (node.superClass.object.type === 'Identifier' &&
|
|
89
|
-
node.superClass.object.name === 'React' &&
|
|
90
|
-
node.superClass.property.type === 'Identifier' &&
|
|
91
|
-
(node.superClass.property.name === 'Component' || node.superClass.property.name === 'PureComponent'));
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
function hasPropsUsage(node) {
|
|
96
|
-
for (const member of node.body.body) {
|
|
97
|
-
if (member.type === 'MethodDefinition') {
|
|
98
|
-
const body = member.value.body;
|
|
99
|
-
if (containsPropsAccess(body)) {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
function containsPropsAccess(node, visited = new Set()) {
|
|
107
|
-
if (!node)
|
|
108
|
-
return false;
|
|
109
|
-
if (visited.has(node))
|
|
110
|
-
return false;
|
|
111
|
-
visited.add(node);
|
|
112
|
-
if (node.type === 'MemberExpression' &&
|
|
113
|
-
node.object.type === 'ThisExpression' &&
|
|
114
|
-
node.property.type === 'Identifier' &&
|
|
115
|
-
node.property.name === 'props') {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
const skipKeys = new Set(['parent', 'range', 'loc', 'start', 'end', 'tokens', 'comments']);
|
|
119
|
-
for (const key in node) {
|
|
120
|
-
if (skipKeys.has(key))
|
|
121
|
-
continue;
|
|
122
|
-
const child = node[key];
|
|
123
|
-
if (child && typeof child === 'object') {
|
|
124
|
-
if (Array.isArray(child)) {
|
|
125
|
-
for (const item of child) {
|
|
126
|
-
if (item && typeof item === 'object' && 'type' in item) {
|
|
127
|
-
if (containsPropsAccess(item, visited)) {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else if ('type' in child) {
|
|
134
|
-
if (containsPropsAccess(child, visited)) {
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.propTypes=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.propTypes=(0,eslint_devkit_1.createRule)({name:"prop-types",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/prop-types.md",description:"Enforce prop types usage"},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string"}},customValidators:{type:"array",items:{type:"string"}},skipUndeclared:{type:"boolean"}},additionalProperties:false}],messages:{propTypes:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Missing PropTypes",description:"Component missing prop type validation",severity:"MEDIUM",fix:"Add propTypes static property or use TypeScript",documentationLink:"https://react.dev/learn/components-and-props#specifying-a-default-prop"})}},defaultOptions:[{}],create(context){const[options]=context.options;const ignore=options?.ignore??[];const skipUndeclared=options?.skipUndeclared??false;const components=[];const propTypesMap=new Map;return{ClassDeclaration(node){if(isReactComponent(node)&&!ignore.includes(node.id?.name||"")){components.push(node)}},'PropertyDefinition[key.name="propTypes"]'(node){if(node.parent.type==="ClassBody"){const classNode=node.parent.parent;if(classNode.id?.name){propTypesMap.set(classNode.id.name,node)}}},"Program:exit"(){for(const component of components){const componentName=component.id?.name;if(!componentName)continue;const propTypesProp=propTypesMap.get(componentName);if(propTypesProp||skipUndeclared&&!hasPropsUsage(component)){continue}context.report({node:component.id||component,messageId:"propTypes"})}}};function isReactComponent(node){if(!node.superClass)return false;if(node.superClass.type==="Identifier"){return node.superClass.name==="Component"||node.superClass.name==="PureComponent"}if(node.superClass.type==="MemberExpression"){return node.superClass.object.type==="Identifier"&&node.superClass.object.name==="React"&&node.superClass.property.type==="Identifier"&&(node.superClass.property.name==="Component"||node.superClass.property.name==="PureComponent")}return false}function hasPropsUsage(node){for(const member of node.body.body){if(member.type==="MethodDefinition"){const body=member.value.body;if(containsPropsAccess(body)){return true}}}return false}function containsPropsAccess(node,visited=new Set){if(!node)return false;if(visited.has(node))return false;visited.add(node);if(node.type==="MemberExpression"&&node.object.type==="ThisExpression"&&node.property.type==="Identifier"&&node.property.name==="props"){return true}const skipKeys=new Set(["parent","range","loc","start","end","tokens","comments"]);for(const key in node){if(skipKeys.has(key))continue;const child=node[key];if(child&&typeof child==="object"){if(Array.isArray(child)){for(const item of child){if(item&&typeof item==="object"&&"type"in item){if(containsPropsAccess(item,visited)){return true}}}}else if("type"in child){if(containsPropsAccess(child,visited)){return true}}}}return false}}});
|