File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -4500,6 +4500,15 @@ function quux (foo) {}
45004500/** @jsxImportSource preact */
45014501/** @jsxRuntime automatic */
45024502// Message: Invalid JSDoc tag name "jsx".
4503+
4504+ /**
4505+ * @constructor
4506+ */
4507+ function Test() {
4508+ this.works = false;
4509+ }
4510+ // Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
4511+ // Message: Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "class".
45034512````
45044513
45054514The following patterns are not considered problems:
Original file line number Diff line number Diff line change @@ -396,7 +396,7 @@ const getPreferredTagName = (
396396 } ) ,
397397 ) ;
398398
399- if ( name in tagPreferenceFixed ) {
399+ if ( Object . prototype . hasOwnProperty . call ( tagPreferenceFixed , name ) ) {
400400 return tagPreferenceFixed [ name ] ;
401401 }
402402
Original file line number Diff line number Diff line change @@ -10,6 +10,12 @@ describe('jsdocUtils', () => {
1010 it ( 'returns the primary tag name' , ( ) => {
1111 expect ( jsdocUtils . getPreferredTagName ( { } , 'jsdoc' , 'return' ) ) . to . equal ( 'returns' ) ;
1212 } ) ;
13+ it ( 'works with the constructor tag' , ( ) => {
14+ expect ( jsdocUtils . getPreferredTagName ( { } , 'jsdoc' , 'constructor' ) ) . to . equal ( 'class' ) ;
15+ } ) ;
16+ } ) ;
17+ it ( 'works with tags that clash with prototype properties' , ( ) => {
18+ expect ( jsdocUtils . getPreferredTagName ( { } , 'jsdoc' , 'toString' ) ) . to . equal ( 'toString' ) ;
1319 } ) ;
1420 it ( 'returns the primary tag name' , ( ) => {
1521 expect ( jsdocUtils . getPreferredTagName ( { } , 'jsdoc' , 'returns' ) ) . to . equal ( 'returns' ) ;
Original file line number Diff line number Diff line change @@ -641,6 +641,37 @@ export default {
641641 } ,
642642 ] ,
643643 } ,
644+ {
645+ code : `
646+ /**
647+ * @constructor
648+ */
649+ function Test() {
650+ this.works = false;
651+ }
652+ ` ,
653+ errors : [
654+ {
655+ line : 3 ,
656+ message : 'Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "class".' ,
657+ } ,
658+ ] ,
659+ output : `
660+ /**
661+ * @class
662+ */
663+ function Test() {
664+ this.works = false;
665+ }
666+ ` ,
667+ settings : {
668+ jsdoc : {
669+ tagNamePreference : {
670+ returns : 'return' ,
671+ } ,
672+ } ,
673+ } ,
674+ } ,
644675 ] ,
645676 valid : [
646677 {
You can’t perform that action at this time.
0 commit comments