@@ -57,7 +57,7 @@ const extendedOptions = [{
5757} ] ;
5858
5959const customOptions = [ {
60- checkProperties : false ,
60+ checkProperties : true ,
6161
6262 checkDefaultAndNamespaceImports : true ,
6363 checkShorthandImports : true ,
@@ -94,6 +94,10 @@ const dontCheckVariablesOptions = [{
9494 checkVariables : false
9595} ] ;
9696
97+ const checkPropertiesOptions = [ {
98+ checkProperties : true
99+ } ] ;
100+
97101ruleTester . run ( 'prevent-abbreviations' , rule , {
98102 valid : [
99103 'let x' ,
@@ -137,6 +141,46 @@ ruleTester.run('prevent-abbreviations', rule, {
137141 'let isJPEG' ,
138142 'let NODE_ENV' ,
139143
144+ // Property should not report by default
145+ '({err: 1})' ,
146+ '({e: 1})' ,
147+ 'this.e = 1' ,
148+ '({e() {}})' ,
149+ '(class {e() {}})' ,
150+ 'this.eResDir = 1' ,
151+ 'this.err = 1' ,
152+ '({err() {}})' ,
153+ '(class {err() {}})' ,
154+ 'this.errCbOptsObj = 1' ,
155+ 'this.successCb = 1' ,
156+ 'this.btnColor = 1' ,
157+ '({evt: 1})' ,
158+ 'foo.evt = 1' ,
159+ outdent `
160+ const foo = {
161+ err() {}
162+ };
163+ ` ,
164+ 'foo.err = 1' ,
165+ 'foo.bar.err = 1' ,
166+ 'this.err = 1' ,
167+ outdent `
168+ class C {
169+ err() {}
170+ }
171+ ` ,
172+ 'this._err = 1' ,
173+ 'this.__err__ = 1' ,
174+ 'this.e_ = 1' ,
175+ '({Err: 1})' ,
176+ '({Res: 1})' ,
177+ 'Foo.customProps = {}' ,
178+ outdent `
179+ class Foo {
180+ static getDerivedContextFromProps() {}
181+ }
182+ ` ,
183+
140184 // Accessing banned names is allowed (as in `camelcase` rule)
141185 'foo.err' ,
142186 'foo.err()' ,
@@ -169,11 +213,6 @@ ruleTester.run('prevent-abbreviations', rule, {
169213 options : extendedOptions
170214 } ,
171215
172- {
173- code : '({err: 1})' ,
174- options : customOptions
175- } ,
176-
177216 {
178217 code : 'let err' ,
179218 options : dontCheckVariablesOptions
@@ -210,22 +249,27 @@ ruleTester.run('prevent-abbreviations', rule, {
210249 } ) ,
211250 noFixingTestCase ( {
212251 code : '({e: 1})' ,
252+ options : checkPropertiesOptions ,
213253 errors : createErrors ( 'Please rename the property `e`. Suggested names are: `error`, `event`. A more descriptive name will do too.' )
214254 } ) ,
215255 noFixingTestCase ( {
216256 code : 'this.e = 1' ,
257+ options : checkPropertiesOptions ,
217258 errors : createErrors ( 'Please rename the property `e`. Suggested names are: `error`, `event`. A more descriptive name will do too.' )
218259 } ) ,
219260 noFixingTestCase ( {
220261 code : '({e() {}})' ,
262+ options : checkPropertiesOptions ,
221263 errors : createErrors ( 'Please rename the property `e`. Suggested names are: `error`, `event`. A more descriptive name will do too.' )
222264 } ) ,
223265 noFixingTestCase ( {
224266 code : '(class {e() {}})' ,
267+ options : checkPropertiesOptions ,
225268 errors : createErrors ( 'Please rename the property `e`. Suggested names are: `error`, `event`. A more descriptive name will do too.' )
226269 } ) ,
227270 noFixingTestCase ( {
228271 code : 'this.eResDir = 1' ,
272+ options : checkPropertiesOptions ,
229273 errors : createErrors ( 'Please rename the property `eResDir`. Suggested names are: `errorResponseDirection`, `errorResponseDirectory`, `errorResultDirection`, ... (5 more omitted). A more descriptive name will do too.' )
230274 } ) ,
231275
@@ -241,22 +285,27 @@ ruleTester.run('prevent-abbreviations', rule, {
241285 } ,
242286 noFixingTestCase ( {
243287 code : '({err: 1})' ,
288+ options : checkPropertiesOptions ,
244289 errors : createErrors ( 'The property `err` should be named `error`. A more descriptive name will do too.' )
245290 } ) ,
246291 noFixingTestCase ( {
247292 code : 'this.err = 1' ,
293+ options : checkPropertiesOptions ,
248294 errors : createErrors ( 'The property `err` should be named `error`. A more descriptive name will do too.' )
249295 } ) ,
250296 noFixingTestCase ( {
251297 code : '({err() {}})' ,
298+ options : checkPropertiesOptions ,
252299 errors : createErrors ( 'The property `err` should be named `error`. A more descriptive name will do too.' )
253300 } ) ,
254301 noFixingTestCase ( {
255302 code : '(class {err() {}})' ,
303+ options : checkPropertiesOptions ,
256304 errors : createErrors ( 'The property `err` should be named `error`. A more descriptive name will do too.' )
257305 } ) ,
258306 noFixingTestCase ( {
259307 code : 'this.errCbOptsObj = 1' ,
308+ options : checkPropertiesOptions ,
260309 errors : createErrors ( 'The property `errCbOptsObj` should be named `errorCallbackOptionsObject`. A more descriptive name will do too.' )
261310 } ) ,
262311
@@ -273,10 +322,12 @@ ruleTester.run('prevent-abbreviations', rule, {
273322
274323 noFixingTestCase ( {
275324 code : 'this.successCb = 1' ,
325+ options : checkPropertiesOptions ,
276326 errors : createErrors ( )
277327 } ) ,
278328 noFixingTestCase ( {
279329 code : 'this.btnColor = 1' ,
330+ options : checkPropertiesOptions ,
280331 errors : createErrors ( )
281332 } ) ,
282333
@@ -292,10 +343,12 @@ ruleTester.run('prevent-abbreviations', rule, {
292343 } ,
293344 noFixingTestCase ( {
294345 code : '({evt: 1})' ,
346+ options : checkPropertiesOptions ,
295347 errors : createErrors ( 'The property `evt` should be named `event`. A more descriptive name will do too.' )
296348 } ) ,
297349 noFixingTestCase ( {
298350 code : 'foo.evt = 1' ,
351+ options : checkPropertiesOptions ,
299352 errors : createErrors ( 'The property `evt` should be named `event`. A more descriptive name will do too.' )
300353 } ) ,
301354
@@ -367,11 +420,7 @@ ruleTester.run('prevent-abbreviations', rule, {
367420
368421 noFixingTestCase ( {
369422 code : '({err: 1})' ,
370- errors : createErrors ( )
371- } ) ,
372- noFixingTestCase ( {
373- code : '({err: 1})' ,
374- options : extendedOptions ,
423+ options : checkPropertiesOptions ,
375424 errors : createErrors ( )
376425 } ) ,
377426
@@ -436,12 +485,6 @@ ruleTester.run('prevent-abbreviations', rule, {
436485 errors : createErrors ( )
437486 } ,
438487
439- noFixingTestCase ( {
440- code : '({err: 1})' ,
441- options : dontCheckVariablesOptions ,
442- errors : createErrors ( )
443- } ) ,
444-
445488 noFixingTestCase ( {
446489 code : outdent `
447490 let e;
@@ -606,6 +649,7 @@ ruleTester.run('prevent-abbreviations', rule, {
606649
607650 noFixingTestCase ( {
608651 code : 'const foo = {err: 1}' ,
652+ options : checkPropertiesOptions ,
609653 errors : createErrors ( )
610654 } ) ,
611655 noFixingTestCase ( {
@@ -614,18 +658,22 @@ ruleTester.run('prevent-abbreviations', rule, {
614658 err() {}
615659 };
616660 ` ,
661+ options : checkPropertiesOptions ,
617662 errors : createErrors ( )
618663 } ) ,
619664 noFixingTestCase ( {
620665 code : 'foo.err = 1' ,
666+ options : checkPropertiesOptions ,
621667 errors : createErrors ( )
622668 } ) ,
623669 noFixingTestCase ( {
624670 code : 'foo.bar.err = 1' ,
671+ options : checkPropertiesOptions ,
625672 errors : createErrors ( )
626673 } ) ,
627674 noFixingTestCase ( {
628675 code : 'this.err = 1' ,
676+ options : checkPropertiesOptions ,
629677 errors : createErrors ( )
630678 } ) ,
631679
@@ -635,19 +683,23 @@ ruleTester.run('prevent-abbreviations', rule, {
635683 err() {}
636684 }
637685 ` ,
686+ options : checkPropertiesOptions ,
638687 errors : createErrors ( )
639688 } ) ,
640689
641690 noFixingTestCase ( {
642691 code : 'this._err = 1' ,
692+ options : checkPropertiesOptions ,
643693 errors : createErrors ( 'The property `_err` should be named `_error`. A more descriptive name will do too.' )
644694 } ) ,
645695 noFixingTestCase ( {
646696 code : 'this.__err__ = 1' ,
697+ options : checkPropertiesOptions ,
647698 errors : createErrors ( 'The property `__err__` should be named `__error__`. A more descriptive name will do too.' )
648699 } ) ,
649700 noFixingTestCase ( {
650701 code : 'this.e_ = 1' ,
702+ options : checkPropertiesOptions ,
651703 errors : createErrors ( 'Please rename the property `e_`. Suggested names are: `error_`, `event_`. A more descriptive name will do too.' )
652704 } ) ,
653705
@@ -692,10 +744,12 @@ ruleTester.run('prevent-abbreviations', rule, {
692744 } ,
693745 noFixingTestCase ( {
694746 code : '({Err: 1})' ,
747+ options : checkPropertiesOptions ,
695748 errors : createErrors ( 'The property `Err` should be named `Error`. A more descriptive name will do too.' )
696749 } ) ,
697750 noFixingTestCase ( {
698751 code : '({Res: 1})' ,
752+ options : checkPropertiesOptions ,
699753 errors : createErrors ( 'Please rename the property `Res`. Suggested names are: `Response`, `Result`. A more descriptive name will do too.' )
700754 } ) ,
701755
@@ -1015,6 +1069,12 @@ moduleRuleTester.run('prevent-abbreviations', rule, {
10151069 valid : [
10161070 'import {err as foo} from "foo"' ,
10171071
1072+ // Property should not report by default
1073+ outdent `
1074+ let foo;
1075+ export {foo as err};
1076+ ` ,
1077+
10181078 // Default import names are allowed
10191079 'import err from "err"' ,
10201080 'import err, {foo as bar} from "err"' ,
@@ -1177,6 +1237,7 @@ moduleRuleTester.run('prevent-abbreviations', rule, {
11771237 let foo;
11781238 export {foo as err};
11791239 ` ,
1240+ options : checkPropertiesOptions ,
11801241 errors : createErrors ( )
11811242 } )
11821243 ]
@@ -1191,12 +1252,27 @@ babelRuleTester.run('prevent-abbreviations', rule, {
11911252 static propTypes = {};
11921253 static getDerivedStateFromProps() {}
11931254 }
1255+ ` ,
1256+
1257+ // Property should not report by default
1258+ outdent `
1259+ class Foo {
1260+ static propTypesAndStuff = {};
1261+ }
1262+ ` ,
1263+ '(class {e = 1})' ,
1264+ '(class {err = 1})' ,
1265+ outdent `
1266+ class C {
1267+ err = () => {}
1268+ }
11941269 `
11951270 ] ,
11961271
11971272 invalid : [
11981273 {
11991274 code : 'Foo.customProps = {}' ,
1275+ options : checkPropertiesOptions ,
12001276 errors : createErrors ( )
12011277 } ,
12021278 {
@@ -1205,6 +1281,7 @@ babelRuleTester.run('prevent-abbreviations', rule, {
12051281 static propTypesAndStuff = {};
12061282 }
12071283 ` ,
1284+ options : checkPropertiesOptions ,
12081285 errors : createErrors ( )
12091286 } ,
12101287 {
@@ -1213,15 +1290,18 @@ babelRuleTester.run('prevent-abbreviations', rule, {
12131290 static getDerivedContextFromProps() {}
12141291 }
12151292 ` ,
1293+ options : checkPropertiesOptions ,
12161294 errors : createErrors ( )
12171295 } ,
12181296
12191297 noFixingTestCase ( {
12201298 code : '(class {e = 1})' ,
1299+ options : checkPropertiesOptions ,
12211300 errors : createErrors ( 'Please rename the property `e`. Suggested names are: `error`, `event`. A more descriptive name will do too.' )
12221301 } ) ,
12231302 noFixingTestCase ( {
12241303 code : '(class {err = 1})' ,
1304+ options : checkPropertiesOptions ,
12251305 errors : createErrors ( 'The property `err` should be named `error`. A more descriptive name will do too.' )
12261306 } ) ,
12271307 noFixingTestCase ( {
@@ -1230,6 +1310,7 @@ babelRuleTester.run('prevent-abbreviations', rule, {
12301310 err = () => {}
12311311 }
12321312 ` ,
1313+ options : checkPropertiesOptions ,
12331314 errors : createErrors ( )
12341315 } )
12351316 ]
0 commit comments