Best JavaScript code snippet using playwright-internal
constants.js
Source:constants.js  
1HTML5 = (typeof HTML5 === 'undefined' ? {} : HTML5);2HTML5.CONTENT_MODEL_FLAGS = [3  'PCDATA',4  'RCDATA',5  'CDATA',6  'SCRIPT_CDATA',7  'PLAINTEXT'8];9HTML5.Marker = {type: 'Marker', data: 'this is a marker token'};10(function() {11  function EOF() {12  }13  EOF.prototype = {14    toString: function() { throw new Error("EOF added as string"); }15  };16  HTML5.EOF = new EOF();17})();18HTML5.EOF_TOK = {type: 'EOF', data: 'End of File' };19HTML5.DRAIN = -2;20HTML5.SCOPING_ELEMENTS = [21  'applet', 'caption', 'html', 'table', 'td', 'th',22  'marquee', 'object', 'math:mi', 'math:mo', 'math:mn', 'math:ms', 'math:mtext',23  'math:annotation-xml', 'svg:foreignObject', 'svg:desc', 'svg:title'24];25HTML5.LIST_SCOPING_ELEMENTS = [26  'ol', 'ul',27  'applet', 'caption', 'html', 'table', 'td', 'th',28  'marquee', 'object', 'math:mi', 'math:mo', 'math:mn', 'math:ms', 'math:mtext',29  'math:annotation-xml', 'svg:foreignObject', 'svg:desc', 'svg:title'30];31HTML5.BUTTON_SCOPING_ELEMENTS = [32  'button',33  'applet', 'caption', 'html', 'table', 'td', 'th',34  'marquee', 'object', 'math:mi', 'math:mo', 'math:mn', 'math:ms', 'math:mtext',35  'math:annotation-xml', 'svg:foreignObject', 'svg:desc', 'svg:title'36];37HTML5.TABLE_SCOPING_ELEMENTS = [38  'table', 'html'39];40HTML5.SELECT_SCOPING_ELEMENTS = [41  'option', 'optgroup'42];43HTML5.FORMATTING_ELEMENTS = [44  'a',45  'b',46  'big',47  'code',48  'em',49  'font',50  'i',51  'nobr',52  's',53  'small',54  'strike',55  'strong',56  'tt',57  'u'58];59HTML5.SPECIAL_ELEMENTS = [60  'address',61  'area',62  'base',63  'basefont',64  'bgsound',65  'blockquote',66  'body',67  'br',68  'center',69  'col',70  'colgroup',71  'dd',72  'dir',73  'div',74  'dl',75  'dt',76  'embed',77  'fieldset',78  'form',79  'frame',80  'frameset',81  'h1',82  'h2',83  'h3',84  'h4',85  'h5',86  'h6',87  'head',88  'hr',89  'iframe',90  'image',91  'img',92  'input',93  'isindex',94  'li',95  'link',96  'listing',97  'menu',98  'meta',99  'noembed',100  'noframes',101  'noscript',102  'ol',103  'optgroup',104  'option',105  'p',106  'param',107  'plaintext',108  'pre',109  'script',110  'select',111  'spacer',112  'style',113  'tbody',114  'textarea',115  'tfoot',116  'thead',117  'title',118  'tr',119  'ul',120  'wbr'121];122HTML5.SPACE_CHARACTERS_IN = "\t\n\x0B\x0C\x20\u0012\r";123HTML5.SPACE_CHARACTERS = "[\t\n\x0B\x0C\x20\r]";124HTML5.SPACE_CHARACTERS_R = /^[\t\n\x0B\x0C \r]/;125HTML5.TABLE_INSERT_MODE_ELEMENTS = [126  'table',127  'tbody',128  'tfoot',129  'thead',130  'tr'131];132HTML5.ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';133HTML5.ASCII_UPPERCASE = HTML5.ASCII_LOWERCASE.toUpperCase();134HTML5.ASCII_LETTERS = "[a-zA-Z]";135HTML5.ASCII_LETTERS_R = /^[a-zA-Z]/;136HTML5.DIGITS = '0123456789';137HTML5.DIGITS_R = new RegExp('^[0123456789]');138HTML5.HEX_DIGITS = HTML5.DIGITS + 'abcdefABCDEF';139HTML5.HEX_DIGITS_R = new RegExp('^[' + HTML5.DIGITS + 'abcdefABCDEF' +']' );140// Heading elements need to be ordered141HTML5.HEADING_ELEMENTS = [142  'h1',143  'h2',144  'h3',145  'h4',146  'h5',147  'h6'148];149HTML5.VOID_ELEMENTS = [150  'base',151  'link',152  'meta',153  'hr',154  'br',155  'img',156  'embed',157  'param',158  'area',159  'col',160  'input'161];162HTML5.CDATA_ELEMENTS = [163  'title',164  'textarea'165];166HTML5.RCDATA_ELEMENTS = [167  'style',168  'script',169  'xmp',170  'iframe',171  'noembed',172  'noframes',173  'noscript'174];175HTML5.BOOLEAN_ATTRIBUTES = {176  '_global': ['irrelevant'],177  // Fixme?178  'style': ['scoped'],179  'img': ['ismap'],180  'audio': ['autoplay', 'controls'],181  'video': ['autoplay', 'controls'],182  'script': ['defer', 'async'],183  'details': ['open'],184  'datagrid': ['multiple', 'disabled'],185  'command': ['hidden', 'disabled', 'checked', 'default'],186  'menu': ['autosubmit'],187  'fieldset': ['disabled', 'readonly'],188  'option': ['disabled', 'readonly', 'selected'],189  'optgroup': ['disabled', 'readonly'],190  'button': ['disabled', 'autofocus'],191  'input': ['disabled', 'readonly', 'required', 'autofocus', 'checked', 'ismap'],192  'select': ['disabled', 'readonly', 'autofocus', 'multiple'],193  'output': ['disabled', 'readonly']194};195HTML5.ENCODINGS = [196  'ansi_x3.4-1968',197  'iso-ir-6',198  'ansi_x3.4-1986',199  'iso_646.irv:1991',200  'ascii',201  'iso646-us',202  'us-ascii',203  'us',204  'ibm367',205  'cp367',206  'csascii',207  'ks_c_5601-1987',208  'korean',209  'iso-2022-kr',210  'csiso2022kr',211  'euc-kr',212  'iso-2022-jp',213  'csiso2022jp',214  'iso-2022-jp-2',215  '',216  'iso-ir-58',217  'chinese',218  'csiso58gb231280',219  'iso_8859-1:1987',220  'iso-ir-100',221  'iso_8859-1',222  'iso-8859-1',223  'latin1',224  'l1',225  'ibm819',226  'cp819',227  'csisolatin1',228  'iso_8859-2:1987',229  'iso-ir-101',230  'iso_8859-2',231  'iso-8859-2',232  'latin2',233  'l2',234  'csisolatin2',235  'iso_8859-3:1988',236  'iso-ir-109',237  'iso_8859-3',238  'iso-8859-3',239  'latin3',240  'l3',241  'csisolatin3',242  'iso_8859-4:1988',243  'iso-ir-110',244  'iso_8859-4',245  'iso-8859-4',246  'latin4',247  'l4',248  'csisolatin4',249  'iso_8859-6:1987',250  'iso-ir-127',251  'iso_8859-6',252  'iso-8859-6',253  'ecma-114',254  'asmo-708',255  'arabic',256  'csisolatinarabic',257  'iso_8859-7:1987',258  'iso-ir-126',259  'iso_8859-7',260  'iso-8859-7',261  'elot_928',262  'ecma-118',263  'greek',264  'greek8',265  'csisolatingreek',266  'iso_8859-8:1988',267  'iso-ir-138',268  'iso_8859-8',269  'iso-8859-8',270  'hebrew',271  'csisolatinhebrew',272  'iso_8859-5:1988',273  'iso-ir-144',274  'iso_8859-5',275  'iso-8859-5',276  'cyrillic',277  'csisolatincyrillic',278  'iso_8859-9:1989',279  'iso-ir-148',280  'iso_8859-9',281  'iso-8859-9',282  'latin5',283  'l5',284  'csisolatin5',285  'iso-8859-10',286  'iso-ir-157',287  'l6',288  'iso_8859-10:1992',289  'csisolatin6',290  'latin6',291  'hp-roman8',292  'roman8',293  'r8',294  'ibm037',295  'cp037',296  'csibm037',297  'ibm424',298  'cp424',299  'csibm424',300  'ibm437',301  'cp437',302  '437',303  'cspc8codepage437',304  'ibm500',305  'cp500',306  'csibm500',307  'ibm775',308  'cp775',309  'cspc775baltic',310  'ibm850',311  'cp850',312  '850',313  'cspc850multilingual',314  'ibm852',315  'cp852',316  '852',317  'cspcp852',318  'ibm855',319  'cp855',320  '855',321  'csibm855',322  'ibm857',323  'cp857',324  '857',325  'csibm857',326  'ibm860',327  'cp860',328  '860',329  'csibm860',330  'ibm861',331  'cp861',332  '861',333  'cp-is',334  'csibm861',335  'ibm862',336  'cp862',337  '862',338  'cspc862latinhebrew',339  'ibm863',340  'cp863',341  '863',342  'csibm863',343  'ibm864',344  'cp864',345  'csibm864',346  'ibm865',347  'cp865',348  '865',349  'csibm865',350  'ibm866',351  'cp866',352  '866',353  'csibm866',354  'ibm869',355  'cp869',356  '869',357  'cp-gr',358  'csibm869',359  'ibm1026',360  'cp1026',361  'csibm1026',362  'koi8-r',363  'cskoi8r',364  'koi8-u',365  'big5-hkscs',366  'ptcp154',367  'csptcp154',368  'pt154',369  'cp154',370  'utf-7',371  'utf-16be',372  'utf-16le',373  'utf-16',374  'utf-8',375  'iso-8859-13',376  'iso-8859-14',377  'iso-ir-199',378  'iso_8859-14:1998',379  'iso_8859-14',380  'latin8',381  'iso-celtic',382  'l8',383  'iso-8859-15',384  'iso_8859-15',385  'iso-8859-16',386  'iso-ir-226',387  'iso_8859-16:2001',388  'iso_8859-16',389  'latin10',390  'l10',391  'gbk',392  'cp936',393  'ms936',394  'gb18030',395  'shift_jis',396  'ms_kanji',397  'csshiftjis',398  'euc-jp',399  'gb2312',400  'big5',401  'csbig5',402  'windows-1250',403  'windows-1251',404  'windows-1252',405  'windows-1253',406  'windows-1254',407  'windows-1255',408  'windows-1256',409  'windows-1257',410  'windows-1258',411  'tis-620',412  'hz-gb-2312'413];414HTML5.E = {415  "null-character":416  "Null character in input stream, replaced with U+FFFD.",417  "incorrectly-placed-solidus":418  "Solidus (/) incorrectly placed in tag.",419  "incorrect-cr-newline-entity":420  "Incorrect CR newline entity, replaced with LF.",421  "illegal-windows-1252-entity":422  "Entity used with illegal number (windows-1252 reference).",423  "cant-convert-numeric-entity":424  "Numeric entity couldn't be converted to character " +425    "(codepoint U+%(charAsInt)08x).",426  "illegal-codepoint-for-numeric-entity":427  "Numeric entity represents an illegal codepoint=> " +428    "U+%(charAsInt)08x.",429  "numeric-entity-without-semicolon":430  "Numeric entity didn't end with ';'.",431  "expected-numeric-entity-but-got-eof":432  "Numeric entity expected. Got end of file instead.",433  "expected-numeric-entity":434  "Numeric entity expected but none found.",435  "named-entity-without-semicolon":436  "Named entity didn't end with ';'.",437  "expected-named-entity":438  "Named entity expected. Got none.",439  "attributes-in-end-tag":440  "End tag contains unexpected attributes.",441  "expected-tag-name-but-got-right-bracket":442  "Expected tag name. Got '>' instead.",443  "expected-tag-name-but-got-question-mark":444  "Expected tag name. Got '?' instead. (HTML doesn't " +445    "support processing instructions.)",446  "expected-tag-name":447  "Expected tag name. Got something else instead",448  "expected-closing-tag-but-got-right-bracket":449  "Expected closing tag. Got '>' instead. Ignoring '</>'.",450  "expected-closing-tag-but-got-eof":451  "Expected closing tag. Unexpected end of file.",452  "expected-closing-tag-but-got-char":453  "Expected closing tag. Unexpected character '%(data)' found.",454  "eof-in-tag-name":455  "Unexpected end of file in the tag name.",456  "expected-attribute-name-but-got-eof":457  "Unexpected end of file. Expected attribute name instead.",458  "eof-in-attribute-name":459  "Unexpected end of file in attribute name.",460  "duplicate-attribute":461  "Dropped duplicate attribute on tag.",462  "expected-end-of-tag-name-but-got-eof":463  "Unexpected end of file. Expected = or end of tag.",464  "expected-attribute-value-but-got-eof":465  "Unexpected end of file. Expected attribute value.",466  "eof-in-attribute-value-double-quote":467  "Unexpected end of file in attribute value (\").",468  "eof-in-attribute-value-single-quote":469  "Unexpected end of file in attribute value (').",470  "eof-in-attribute-value-no-quotes":471  "Unexpected end of file in attribute value.",472  "expected-dashes-or-doctype":473  "Expected '--' or 'DOCTYPE'. Not found.",474  "incorrect-comment":475  "Incorrect comment.",476  "eof-in-comment":477  "Unexpected end of file in comment.",478  "eof-in-comment-end-dash":479  "Unexpected end of file in comment (-)",480  "unexpected-dash-after-double-dash-in-comment":481  "Unexpected '-' after '--' found in comment.",482  "eof-in-comment-double-dash":483  "Unexpected end of file in comment (--).",484  "unexpected-char-in-comment":485  "Unexpected character in comment found.",486  "need-space-after-doctype":487  "No space after literal string 'DOCTYPE'.",488  "expected-doctype-name-but-got-right-bracket":489  "Unexpected > character. Expected DOCTYPE name.",490  "expected-doctype-name-but-got-eof":491  "Unexpected end of file. Expected DOCTYPE name.",492  "eof-in-doctype-name":493  "Unexpected end of file in DOCTYPE name.",494  "eof-in-doctype":495  "Unexpected end of file in DOCTYPE.",496  "expected-space-or-right-bracket-in-doctype":497  "Expected space or '>'. Got '%(data)'",498  "unexpected-end-of-doctype":499  "Unexpected end of DOCTYPE.",500  "unexpected-char-in-doctype":501  "Unexpected character in DOCTYPE.",502  "eof-in-bogus-doctype":503  "Unexpected end of file in bogus doctype.",504  "eof-in-innerhtml":505  "Unexpected EOF in inner html mode.",506  "unexpected-doctype":507  "Unexpected DOCTYPE. Ignored.",508  "non-html-root":509  "html needs to be the first start tag.",510  "expected-doctype-but-got-eof":511  "Unexpected End of file. Expected DOCTYPE.",512  "unknown-doctype":513  "Erroneous DOCTYPE.",514  "expected-doctype-but-got-chars":515  "Unexpected non-space characters. Expected DOCTYPE.",516  "expected-doctype-but-got-start-tag":517  "Unexpected start tag (%(name)). Expected DOCTYPE.",518  "expected-doctype-but-got-end-tag":519  "Unexpected end tag (%(name)). Expected DOCTYPE.",520  "end-tag-after-implied-root":521  "Unexpected end tag (%(name)) after the (implied) root element.",522  "expected-named-closing-tag-but-got-eof":523  "Unexpected end of file. Expected end tag (%(name)).",524  "two-heads-are-not-better-than-one":525  "Unexpected start tag head in existing head. Ignored.",526  "unexpected-end-tag":527  "Unexpected end tag (%(name)). Ignored.",528  "unexpected-start-tag-out-of-my-head":529  "Unexpected start tag (%(name)) that can be in head. Moved.",530  "unexpected-start-tag":531  "Unexpected start tag (%(name)).",532  "missing-end-tag":533  "Missing end tag (%(name)).",534  "missing-end-tags":535  "Missing end tags (%(name)).",536  "unexpected-start-tag-implies-end-tag":537  "Unexpected start tag (%(startName)) " +538    "implies end tag (%(endName)).",539  "unexpected-start-tag-treated-as":540  "Unexpected start tag (%(originalName)). Treated as %(newName).",541  "deprecated-tag":542  "Unexpected start tag %(name). Don't use it!",543  "unexpected-start-tag-ignored":544  "Unexpected start tag %(name). Ignored.",545  "expected-one-end-tag-but-got-another":546  "Unexpected end tag (%(gotName). " +547    "Missing end tag (%(expectedName)).",548  "end-tag-too-early":549  "End tag (%(name)) seen too early. Expected other end tag.",550  "end-tag-too-early-named":551  "Unexpected end tag (%(gotName)). Expected end tag (%(expectedName).",552  "end-tag-too-early-ignored":553  "End tag (%(name)) seen too early. Ignored.",554  "adoption-agency-1.1":555  "End tag (%(name) violates step 1, " +556    "paragraph 1 of the adoption agency algorithm.",557  "adoption-agency-1.2":558  "End tag (%(name) violates step 1, " +559    "paragraph 2 of the adoption agency algorithm.",560  "adoption-agency-1.3":561  "End tag (%(name) violates step 1, " +562    "paragraph 3 of the adoption agency algorithm.",563  "unexpected-end-tag-treated-as":564  "Unexpected end tag (%(originalName)). Treated as %(newName).",565  "no-end-tag":566  "This element (%(name)) has no end tag.",567  "unexpected-implied-end-tag-in-table":568  "Unexpected implied end tag (%(name)) in the table phase.",569  "unexpected-implied-end-tag-in-table-body":570  "Unexpected implied end tag (%(name)) in the table body phase.",571  "unexpected-char-implies-table-voodoo":572  "Unexpected non-space characters in " +573    "table context caused voodoo mode.",574  "unpexted-hidden-input-in-table":575  "Unexpected input with type hidden in table context.",576  "unexpected-start-tag-implies-table-voodoo":577  "Unexpected start tag (%(name)) in " +578    "table context caused voodoo mode.",579  "unexpected-end-tag-implies-table-voodoo":580  "Unexpected end tag (%(name)) in " +581    "table context caused voodoo mode.",582  "unexpected-cell-in-table-body":583  "Unexpected table cell start tag (%(name)) " +584    "in the table body phase.",585  "unexpected-cell-end-tag":586  "Got table cell end tag (%(name)) " +587    "while required end tags are missing.",588  "unexpected-end-tag-in-table-body":589  "Unexpected end tag (%(name)) in the table body phase. Ignored.",590  "unexpected-implied-end-tag-in-table-row":591  "Unexpected implied end tag (%(name)) in the table row phase.",592  "unexpected-end-tag-in-table-row":593  "Unexpected end tag (%(name)) in the table row phase. Ignored.",594  "unexpected-select-in-select":595  "Unexpected select start tag in the select phase " +596    "treated as select end tag.",597  "unexpected-input-in-select":598  "Unexpected input start tag in the select phase.",599  "unexpected-start-tag-in-select":600  "Unexpected start tag token (%(name)) in the select phase. " +601    "Ignored.",602  "unexpected-end-tag-in-select":603  "Unexpected end tag (%(name)) in the select phase. Ignored.",604  "unexpected-table-element-start-tag-in-select-in-table":605  "Unexpected table element start tag (%(name))s in the select in table phase.",606  "unexpected-table-element-end-tag-in-select-in-table":607  "Unexpected table element end tag (%(name))s in the select in table phase.",608  "unexpected-char-after-body":609  "Unexpected non-space characters in the after body phase.",610  "unexpected-start-tag-after-body":611  "Unexpected start tag token (%(name))" +612    "in the after body phase.",613  "unexpected-end-tag-after-body":614  "Unexpected end tag token (%(name))" +615    " in the after body phase.",616  "unexpected-char-in-frameset":617  "Unepxected characters in the frameset phase. Characters ignored.",618  "unexpected-start-tag-in-frameset":619  "Unexpected start tag token (%(name))" +620    " in the frameset phase. Ignored.",621  "unexpected-frameset-in-frameset-innerhtml":622  "Unexpected end tag token (frameset " +623    "in the frameset phase (innerHTML).",624  "unexpected-end-tag-in-frameset":625  "Unexpected end tag token (%(name))" +626    " in the frameset phase. Ignored.",627  "unexpected-char-after-frameset":628  "Unexpected non-space characters in the " +629    "after frameset phase. Ignored.",630  "unexpected-start-tag-after-frameset":631  "Unexpected start tag (%(name))" +632    " in the after frameset phase. Ignored.",633  "unexpected-end-tag-after-frameset":634  "Unexpected end tag (%(name))" +635    " in the after frameset phase. Ignored.",636  "expected-eof-but-got-char":637  "Unexpected non-space characters. Expected end of file.",638  "expected-eof-but-got-start-tag":639  "Unexpected start tag (%(name))" +640    ". Expected end of file.",641  "expected-eof-but-got-end-tag":642  "Unexpected end tag (%(name))" +643    ". Expected end of file.",644  "unexpected-end-table-in-caption":645  "Unexpected end table tag in caption. Generates implied end caption.",646  "end-html-in-innerhtml":647  "Unexpected html end tag in inner html mode.",648  "expected-self-closing-tag":649  "Expected a > after the /.",650  "self-closing-end-tag":651  "Self closing end tag.",652  "eof-in-table":653  "Unexpected end of file. Expected table content.",654  "html-in-foreign-content":655  "HTML start tag \"%(name)\" in a foreign namespace context.",656  "unexpected-start-tag-in-table":657  "Unexpected %(name). Expected table content."658};659HTML5.Models = {PCDATA: 'PCDATA', RCDATA: 'RCDATA', CDATA: 'CDATA', SCRIPT_CDATA: 'SCRIPT_CDATA'};660HTML5.TAGMODES = {661  select: 'inSelect',662  td: 'inCell',663  th: 'inCell',664  tr: 'inRow',665  tbody: 'inTableBody',666  thead: 'inTableBody',667  tfoot: 'inTableBody',668  caption: 'inCaption',669  colgroup: 'inColumnGroup',670  table: 'inTable',671  head: 'inBody',672  body: 'inBody',673  frameset: 'inFrameset'674};675HTML5.SVGAttributeMap = {676  attributename:	'attributeName',677  attributetype:	'attributeType',678  basefrequency:	'baseFrequency',679  baseprofile:	'baseProfile',680  calcmode:	'calcMode',681  clippathunits:	'clipPathUnits',682  contentscripttype:	'contentScriptType',683  contentstyletype:	'contentStyleType',684  diffuseconstant:	'diffuseConstant',685  edgemode:	'edgeMode',686  externalresourcesrequired:	'externalResourcesRequired',687  filterres:	'filterRes',688  filterunits:	'filterUnits',689  glyphref:	'glyphRef',690  gradienttransform:	'gradientTransform',691  gradientunits:	'gradientUnits',692  kernelmatrix:	'kernelMatrix',693  kernelunitlength:	'kernelUnitLength',694  keypoints:	'keyPoints',695  keysplines:	'keySplines',696  keytimes:	'keyTimes',697  lengthadjust:	'lengthAdjust',698  limitingconeangle:	'limitingConeAngle',699  markerheight:	'markerHeight',700  markerunits:	'markerUnits',701  markerwidth:	'markerWidth',702  maskcontentunits:	'maskContentUnits',703  maskunits:	'maskUnits',704  numoctaves:	'numOctaves',705  pathlength:	'pathLength',706  patterncontentunits:	'patternContentUnits',707  patterntransform:	'patternTransform',708  patternunits:	'patternUnits',709  pointsatx:	'pointsAtX',710  pointsaty:	'pointsAtY',711  pointsatz:	'pointsAtZ',712  preservealpha:	'preserveAlpha',713  preserveaspectratio:	'preserveAspectRatio',714  primitiveunits:	'primitiveUnits',715  refx:	'refX',716  refy:	'refY',717  repeatcount:	'repeatCount',718  repeatdur:	'repeatDur',719  requiredextensions:	'requiredExtensions',720  requiredfeatures:	'requiredFeatures',721  specularconstant:	'specularConstant',722  specularexponent:	'specularExponent',723  spreadmethod:	'spreadMethod',724  startoffset:	'startOffset',725  stddeviation:	'stdDeviation',726  stitchtiles:	'stitchTiles',727  surfacescale:	'surfaceScale',728  systemlanguage:	'systemLanguage',729  tablevalues:	'tableValues',730  targetx:	'targetX',731  targety:	'targetY',732  textlength:	'textLength',733  viewbox:	'viewBox',734  viewtarget:	'viewTarget',735  xchannelselector:	'xChannelSelector',736  ychannelselector:	'yChannelSelector',737  zoomandpan:	'zoomAndPan'...no-whitespace-before-property.js
Source:no-whitespace-before-property.js  
1/**2 * @fileoverview Rule to disallow whitespace before properties3 * @author Kai Cataldo4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/no-whitespace-before-property"),10    { RuleTester } = require("../../../lib/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("no-whitespace-before-property", rule, {16    valid: [17        "foo.bar",18        "foo.bar()",19        "foo[bar]",20        "foo['bar']",21        "foo[0]",22        "foo[ bar ]",23        "foo[ 'bar' ]",24        "foo[ 0 ]",25        "foo\n.bar",26        "foo.\nbar",27        "foo\n.bar()",28        "foo.\nbar()",29        "foo\n[bar]",30        "foo\n['bar']",31        "foo\n[0]",32        "foo\n[ bar ]",33        "foo.\n bar",34        "foo\n. bar",35        "foo.\n bar()",36        "foo\n. bar()",37        "foo\n [bar]",38        "foo\n ['bar']",39        "foo\n [0]",40        "foo\n [ bar ]",41        "foo.\n\tbar",42        "foo\n.\tbar",43        "foo.\n\tbar()",44        "foo\n.\tbar()",45        "foo\n\t[bar]",46        "foo\n\t['bar']",47        "foo\n\t[0]",48        "foo\n\t[ bar ]",49        "foo.bar.baz",50        "foo\n.bar\n.baz",51        "foo.\nbar.\nbaz",52        "foo.bar().baz()",53        "foo\n.bar()\n.baz()",54        "foo.\nbar().\nbaz()",55        "foo\n.bar\n[baz]",56        "foo\n.bar\n['baz']",57        "foo\n.bar\n[0]",58        "foo\n.bar\n[ baz ]",59        "foo\n .bar\n .baz",60        "foo.\n bar.\n baz",61        "foo\n .bar()\n .baz()",62        "foo.\n bar().\n baz()",63        "foo\n .bar\n [baz]",64        "foo\n .bar\n ['baz']",65        "foo\n .bar\n [0]",66        "foo\n .bar\n [ baz ]",67        "foo\n\t.bar\n\t.baz",68        "foo.\n\tbar.\n\tbaz",69        "foo\n\t.bar()\n\t.baz()",70        "foo.\n\tbar().\n\tbaz()",71        "foo\n\t.bar\n\t[baz]",72        "foo\n\t.bar\n\t['baz']",73        "foo\n\t.bar\n\t[0]",74        "foo\n\t.bar\n\t[ baz ]",75        "foo['bar' + baz]",76        "foo[ 'bar' + baz ]",77        "(foo + bar).baz",78        "( foo + bar ).baz",79        "(foo ? bar : baz).qux",80        "( foo ? bar : baz ).qux",81        "(foo ? bar : baz)[qux]",82        "( foo ? bar : baz )[qux]",83        "( foo ? bar : baz )[0].qux",84        "foo.bar[('baz')]",85        "foo.bar[ ('baz') ]",86        "foo[[bar]]",87        "foo[ [ bar ] ]",88        "foo[['bar']]",89        "foo[ [ 'bar' ] ]",90        "foo[(('baz'))]",91        "foo[ (('baz'))]",92        "foo[0][[('baz')]]",93        "foo[bar.baz('qux')]",94        "foo[(bar.baz() + 0) + qux]",95        "foo['bar ' + 1 + ' baz']",96        "5['toExponential']()"97    ],98    invalid: [99        {100            code: "foo. bar",101            output: "foo.bar",102            errors: ["Unexpected whitespace before property bar."]103        },104        {105            code: "foo .bar",106            output: "foo.bar",107            errors: ["Unexpected whitespace before property bar."]108        },109        {110            code: "foo [bar]",111            output: "foo[bar]",112            errors: ["Unexpected whitespace before property bar."]113        },114        {115            code: "foo [0]",116            output: "foo[0]",117            errors: ["Unexpected whitespace before property 0."]118        },119        {120            code: "foo ['bar']",121            output: "foo['bar']",122            errors: ["Unexpected whitespace before property 'bar'."]123        },124        {125            code: "foo. bar. baz",126            output: "foo.bar.baz",127            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]128        },129        {130            code: "foo .bar. baz",131            output: "foo.bar.baz",132            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]133        },134        {135            code: "foo [bar] [baz]",136            output: "foo[bar][baz]",137            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]138        },139        {140            code: "foo [bar][baz]",141            output: "foo[bar][baz]",142            errors: ["Unexpected whitespace before property bar."]143        },144        {145            code: "foo[bar] [baz]",146            output: "foo[bar][baz]",147            errors: ["Unexpected whitespace before property baz."]148        },149        {150            code: "foo.bar [baz]",151            output: "foo.bar[baz]",152            errors: ["Unexpected whitespace before property baz."]153        },154        {155            code: "foo. bar[baz]",156            output: "foo.bar[baz]",157            errors: ["Unexpected whitespace before property bar."]158        },159        {160            code: "foo[bar]. baz",161            output: "foo[bar].baz",162            errors: ["Unexpected whitespace before property baz."]163        },164        {165            code: "foo[ bar ] [ baz ]",166            output: "foo[ bar ][ baz ]",167            errors: ["Unexpected whitespace before property baz."]168        },169        {170            code: "foo [ 0 ][ baz ]",171            output: "foo[ 0 ][ baz ]",172            errors: ["Unexpected whitespace before property 0."]173        },174        {175            code: "foo[ 0 ] [ 'baz' ]",176            output: "foo[ 0 ][ 'baz' ]",177            errors: ["Unexpected whitespace before property 'baz'."]178        },179        // tabs180        {181            code: "foo\t.bar",182            output: "foo.bar",183            errors: ["Unexpected whitespace before property bar."]184        },185        {186            code: "foo.\tbar",187            output: "foo.bar",188            errors: ["Unexpected whitespace before property bar."]189        },190        {191            code: "foo\t.bar()",192            output: "foo.bar()",193            errors: ["Unexpected whitespace before property bar."]194        },195        {196            code: "foo.\tbar()",197            output: "foo.bar()",198            errors: ["Unexpected whitespace before property bar."]199        },200        {201            code: "foo\t[bar]",202            output: "foo[bar]",203            errors: ["Unexpected whitespace before property bar."]204        },205        {206            code: "foo\t[0]",207            output: "foo[0]",208            errors: ["Unexpected whitespace before property 0."]209        },210        {211            code: "foo\t['bar']",212            output: "foo['bar']",213            errors: ["Unexpected whitespace before property 'bar'."]214        },215        {216            code: "foo.\tbar.\tbaz",217            output: "foo.bar.baz",218            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]219        },220        {221            code: "foo\t.bar.\tbaz",222            output: "foo.bar.baz",223            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]224        },225        {226            code: "foo.\tbar().\tbaz()",227            output: "foo.bar().baz()",228            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]229        },230        {231            code: "foo\t.bar().\tbaz()",232            output: "foo.bar().baz()",233            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]234        },235        {236            code: "foo\t[bar]\t[baz]",237            output: "foo[bar][baz]",238            errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."]239        },240        {241            code: "foo\t[bar][baz]",242            output: "foo[bar][baz]",243            errors: ["Unexpected whitespace before property bar."]244        },245        {246            code: "foo[bar]\t[baz]",247            output: "foo[bar][baz]",248            errors: ["Unexpected whitespace before property baz."]249        },250        {251            code: "foo.bar\t[baz]",252            output: "foo.bar[baz]",253            errors: ["Unexpected whitespace before property baz."]254        },255        {256            code: "foo.\tbar[baz]",257            output: "foo.bar[baz]",258            errors: ["Unexpected whitespace before property bar."]259        },260        {261            code: "foo[bar].\tbaz",262            output: "foo[bar].baz",263            errors: ["Unexpected whitespace before property baz."]264        },265        // newlines266        {267            code: "foo [bar]\n .baz",268            output: "foo[bar]\n .baz",269            errors: ["Unexpected whitespace before property bar."]270        },271        {272            code: "foo. bar\n .baz",273            output: "foo.bar\n .baz",274            errors: ["Unexpected whitespace before property bar."]275        },276        {277            code: "foo .bar\n.baz",278            output: "foo.bar\n.baz",279            errors: ["Unexpected whitespace before property bar."]280        },281        {282            code: "foo.\n bar. baz",283            output: "foo.\n bar.baz",284            errors: ["Unexpected whitespace before property baz."]285        },286        {287            code: "foo.\nbar . baz",288            output: "foo.\nbar.baz",289            errors: ["Unexpected whitespace before property baz."]290        },291        {292            code: "foo. bar()\n .baz()",293            output: "foo.bar()\n .baz()",294            errors: ["Unexpected whitespace before property bar."]295        },296        {297            code: "foo .bar()\n.baz()",298            output: "foo.bar()\n.baz()",299            errors: ["Unexpected whitespace before property bar."]300        },301        {302            code: "foo.\n bar(). baz()",303            output: "foo.\n bar().baz()",304            errors: ["Unexpected whitespace before property baz."]305        },306        {307            code: "foo.\nbar() . baz()",308            output: "foo.\nbar().baz()",309            errors: ["Unexpected whitespace before property baz."]310        },311        {312            code: "foo\t[bar]\n\t.baz",313            output: "foo[bar]\n\t.baz",314            errors: ["Unexpected whitespace before property bar."]315        },316        {317            code: "foo.\tbar\n\t.baz",318            output: "foo.bar\n\t.baz",319            errors: ["Unexpected whitespace before property bar."]320        },321        {322            code: "foo\t.bar\n.baz",323            output: "foo.bar\n.baz",324            errors: ["Unexpected whitespace before property bar."]325        },326        {327            code: "foo.\n\tbar.\tbaz",328            output: "foo.\n\tbar.baz",329            errors: ["Unexpected whitespace before property baz."]330        },331        {332            code: "foo.\nbar\t.\tbaz",333            output: "foo.\nbar.baz",334            errors: ["Unexpected whitespace before property baz."]335        },336        {337            code: "foo.\tbar()\n\t.baz()",338            output: "foo.bar()\n\t.baz()",339            errors: ["Unexpected whitespace before property bar."]340        },341        {342            code: "foo\t.bar()\n.baz()",343            output: "foo.bar()\n.baz()",344            errors: ["Unexpected whitespace before property bar."]345        },346        {347            code: "foo.\n\tbar().\tbaz()",348            output: "foo.\n\tbar().baz()",349            errors: ["Unexpected whitespace before property baz."]350        },351        {352            code: "foo.\nbar()\t.\tbaz()",353            output: "foo.\nbar().baz()",354            errors: ["Unexpected whitespace before property baz."]355        },356        // parens/computed properties357        {358            code: "foo ['bar' + baz]",359            output: "foo['bar' + baz]",360            errors: ["Unexpected whitespace before property 'bar' + baz."]361        },362        {363            code: "(foo + bar) .baz",364            output: "(foo + bar).baz",365            errors: ["Unexpected whitespace before property baz."]366        },367        {368            code: "(foo + bar). baz",369            output: "(foo + bar).baz",370            errors: ["Unexpected whitespace before property baz."]371        },372        {373            code: "(foo + bar) [baz]",374            output: "(foo + bar)[baz]",375            errors: ["Unexpected whitespace before property baz."]376        },377        {378            code: "(foo ? bar : baz) .qux",379            output: "(foo ? bar : baz).qux",380            errors: ["Unexpected whitespace before property qux."]381        },382        {383            code: "(foo ? bar : baz). qux",384            output: "(foo ? bar : baz).qux",385            errors: ["Unexpected whitespace before property qux."]386        },387        {388            code: "(foo ? bar : baz) [qux]",389            output: "(foo ? bar : baz)[qux]",390            errors: ["Unexpected whitespace before property qux."]391        },392        {393            code: "( foo ? bar : baz ) [0].qux",394            output: "( foo ? bar : baz )[0].qux",395            errors: ["Unexpected whitespace before property 0."]396        },397        {398            code: "( foo ? bar : baz )[0] .qux",399            output: "( foo ? bar : baz )[0].qux",400            errors: ["Unexpected whitespace before property qux."]401        },402        {403            code: "( foo ? bar : baz )[0]. qux",404            output: "( foo ? bar : baz )[0].qux",405            errors: ["Unexpected whitespace before property qux."]406        },407        {408            code: "( foo ? bar : baz ) [0]. qux",409            output: "( foo ? bar : baz )[0].qux",410            errors: ["Unexpected whitespace before property qux.", "Unexpected whitespace before property 0."]411        },412        {413            code: "foo.bar [('baz')]",414            output: "foo.bar[('baz')]",415            errors: ["Unexpected whitespace before property 'baz'."]416        },417        {418            code: "foo .bar[('baz')]",419            output: "foo.bar[('baz')]",420            errors: ["Unexpected whitespace before property bar."]421        },422        {423            code: "foo .bar [('baz')]",424            output: "foo.bar[('baz')]",425            errors: ["Unexpected whitespace before property 'baz'.", "Unexpected whitespace before property bar."]426        },427        {428            code: "foo [(('baz'))]",429            output: "foo[(('baz'))]",430            errors: ["Unexpected whitespace before property 'baz'."]431        },432        {433            code: "foo [[baz]]",434            output: "foo[[baz]]",435            errors: ["Unexpected whitespace before property [baz]."]436        },437        {438            code: "foo [ [ baz ] ]",439            output: "foo[ [ baz ] ]",440            errors: ["Unexpected whitespace before property [ baz ]."]441        },442        {443            code: "foo [['baz']]",444            output: "foo[['baz']]",445            errors: ["Unexpected whitespace before property ['baz']."]446        },447        {448            code: "foo [ [ 'baz' ] ]",449            output: "foo[ [ 'baz' ] ]",450            errors: ["Unexpected whitespace before property [ 'baz' ]."]451        },452        {453            code: "foo[0] [[('baz')]]",454            output: "foo[0][[('baz')]]",455            errors: ["Unexpected whitespace before property [('baz')]."]456        },457        {458            code: "foo [0][[('baz')]]",459            output: "foo[0][[('baz')]]",460            errors: ["Unexpected whitespace before property 0."]461        },462        {463            code: "foo [0] [[('baz')]]",464            output: "foo[0][[('baz')]]",465            errors: ["Unexpected whitespace before property [('baz')].", "Unexpected whitespace before property 0."]466        },467        {468            code: "foo [bar.baz('qux')]",469            output: "foo[bar.baz('qux')]",470            errors: ["Unexpected whitespace before property bar.baz('qux')."]471        },472        {473            code: "foo[bar .baz('qux')]",474            output: "foo[bar.baz('qux')]",475            errors: ["Unexpected whitespace before property baz."]476        },477        {478            code: "foo [bar . baz('qux')]",479            output: "foo[bar.baz('qux')]",480            errors: ["Unexpected whitespace before property bar . baz('qux').", "Unexpected whitespace before property baz."]481        },482        {483            code: "foo [(bar.baz() + 0) + qux]",484            output: "foo[(bar.baz() + 0) + qux]",485            errors: ["Unexpected whitespace before property (bar.baz() + 0) + qux."]486        },487        {488            code: "foo[(bar. baz() + 0) + qux]",489            output: "foo[(bar.baz() + 0) + qux]",490            errors: ["Unexpected whitespace before property baz."]491        },492        {493            code: "foo [(bar. baz() + 0) + qux]",494            output: "foo[(bar.baz() + 0) + qux]",495            errors: ["Unexpected whitespace before property (bar. baz() + 0) + qux.", "Unexpected whitespace before property baz."]496        },497        {498            code: "foo ['bar ' + 1 + ' baz']",499            output: "foo['bar ' + 1 + ' baz']",500            errors: ["Unexpected whitespace before property 'bar ' + 1 + ' baz'."]501        },502        {503            code: "5 .toExponential()",504            output: null, // This case is not fixed; can't be sure whether 5..toExponential or (5).toExponential is preferred505            errors: ["Unexpected whitespace before property toExponential."]506        },507        {508            code: "5       .toExponential()",509            output: null, // Not fixed510            errors: ["Unexpected whitespace before property toExponential."]511        },512        {513            code: "5. .toExponential()",514            output: "5..toExponential()",515            errors: ["Unexpected whitespace before property toExponential."]516        },517        {518            code: "5.0 .toExponential()",519            output: "5.0.toExponential()",520            errors: ["Unexpected whitespace before property toExponential."]521        },522        {523            code: "0x5 .toExponential()",524            output: "0x5.toExponential()",525            errors: ["Unexpected whitespace before property toExponential."]526        },527        {528            code: "5e0 .toExponential()",529            output: "5e0.toExponential()",530            errors: ["Unexpected whitespace before property toExponential."]531        },532        {533            code: "5e-0 .toExponential()",534            output: "5e-0.toExponential()",535            errors: ["Unexpected whitespace before property toExponential."]536        },537        {538            code: "5 ['toExponential']()",539            output: "5['toExponential']()",540            errors: ["Unexpected whitespace before property 'toExponential'."]541        },542        {543            code: "05 .toExponential()",544            output: "05.toExponential()",545            errors: ["Unexpected whitespace before property toExponential."]546        }547    ]...no-extra-boolean-cast.js
Source:no-extra-boolean-cast.js  
1/**2 * @fileoverview Tests for no-extra-boolean-cast rule.3 * @author Brandon Mills4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/no-extra-boolean-cast"),10    { RuleTester } = require("../../../lib/rule-tester");11//------------------------------------------------------------------------------12// Helpers13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("no-extra-boolean-cast", rule, {16    valid: [17        "var foo = !!bar;",18        "function foo() { return !!bar; }",19        "var foo = bar() ? !!baz : !!bat",20        "for(!!foo;;) {}",21        "for(;; !!foo) {}",22        "var foo = Boolean(bar);",23        "function foo() { return Boolean(bar); }",24        "var foo = bar() ? Boolean(baz) : Boolean(bat)",25        "for(Boolean(foo);;) {}",26        "for(;; Boolean(foo)) {}",27        "if (new Boolean(foo)) {}"28    ],29    invalid: [30        {31            code: "if (!!foo) {}",32            output: "if (foo) {}",33            errors: [{34                messageId: "unexpectedNegation",35                type: "UnaryExpression",36                column: 5,37                endColumn: 1038            }]39        },40        {41            code: "do {} while (!!foo)",42            output: "do {} while (foo)",43            errors: [{44                messageId: "unexpectedNegation",45                type: "UnaryExpression",46                column: 1447            }]48        },49        {50            code: "while (!!foo) {}",51            output: "while (foo) {}",52            errors: [{53                messageId: "unexpectedNegation",54                type: "UnaryExpression",55                column: 856            }]57        },58        {59            code: "!!foo ? bar : baz",60            output: "foo ? bar : baz",61            errors: [{62                messageId: "unexpectedNegation",63                type: "UnaryExpression",64                column: 165            }]66        },67        {68            code: "for (; !!foo;) {}",69            output: "for (; foo;) {}",70            errors: [{71                messageId: "unexpectedNegation",72                type: "UnaryExpression",73                column: 874            }]75        },76        {77            code: "!!!foo",78            output: "!foo",79            errors: [{80                messageId: "unexpectedNegation",81                type: "UnaryExpression",82                column: 283            }]84        },85        {86            code: "Boolean(!!foo)",87            output: "Boolean(foo)",88            errors: [{89                messageId: "unexpectedNegation",90                type: "UnaryExpression",91                column: 992            }]93        },94        {95            code: "new Boolean(!!foo)",96            output: "new Boolean(foo)",97            errors: [{98                messageId: "unexpectedNegation",99                type: "UnaryExpression",100                column: 13101            }]102        },103        {104            code: "if (Boolean(foo)) {}",105            output: "if (foo) {}",106            errors: [{107                messageId: "unexpectedCall",108                type: "CallExpression"109            }]110        },111        {112            code: "do {} while (Boolean(foo))",113            output: "do {} while (foo)",114            errors: [{115                messageId: "unexpectedCall",116                type: "CallExpression"117            }]118        },119        {120            code: "while (Boolean(foo)) {}",121            output: "while (foo) {}",122            errors: [{123                messageId: "unexpectedCall",124                type: "CallExpression"125            }]126        },127        {128            code: "Boolean(foo) ? bar : baz",129            output: "foo ? bar : baz",130            errors: [{131                messageId: "unexpectedCall",132                type: "CallExpression"133            }]134        },135        {136            code: "for (; Boolean(foo);) {}",137            output: "for (; foo;) {}",138            errors: [{139                messageId: "unexpectedCall",140                type: "CallExpression"141            }]142        },143        {144            code: "!Boolean(foo)",145            output: "!foo",146            errors: [{147                messageId: "unexpectedCall",148                type: "CallExpression"149            }]150        },151        {152            code: "!Boolean(foo && bar)",153            output: "!(foo && bar)",154            errors: [{155                messageId: "unexpectedCall",156                type: "CallExpression"157            }]158        },159        {160            code: "!Boolean(foo + bar)",161            output: "!(foo + bar)",162            errors: [{163                messageId: "unexpectedCall",164                type: "CallExpression"165            }]166        },167        {168            code: "!Boolean(+foo)",169            output: "!+foo",170            errors: [{171                messageId: "unexpectedCall",172                type: "CallExpression"173            }]174        },175        {176            code: "!Boolean(foo())",177            output: "!foo()",178            errors: [{179                messageId: "unexpectedCall",180                type: "CallExpression"181            }]182        },183        {184            code: "!Boolean(foo = bar)",185            output: "!(foo = bar)",186            errors: [{187                messageId: "unexpectedCall",188                type: "CallExpression"189            }]190        },191        {192            code: "!Boolean(...foo);",193            output: null,194            parserOptions: { ecmaVersion: 2015 },195            errors: [{196                messageId: "unexpectedCall",197                type: "CallExpression"198            }]199        },200        {201            code: "!Boolean(foo, bar());",202            output: null,203            errors: [{204                messageId: "unexpectedCall",205                type: "CallExpression"206            }]207        },208        {209            code: "!Boolean((foo, bar()));",210            output: "!(foo, bar());",211            errors: [{212                messageId: "unexpectedCall",213                type: "CallExpression"214            }]215        },216        {217            code: "!Boolean();",218            output: "true;",219            errors: [{220                messageId: "unexpectedCall",221                type: "CallExpression"222            }]223        },224        {225            code: "!(Boolean());",226            output: "true;",227            errors: [{228                messageId: "unexpectedCall",229                type: "CallExpression"230            }]231        },232        {233            code: "if (!Boolean()) { foo() }",234            output: "if (true) { foo() }",235            errors: [{236                messageId: "unexpectedCall",237                type: "CallExpression"238            }]239        },240        {241            code: "while (!Boolean()) { foo() }",242            output: "while (true) { foo() }",243            errors: [{244                messageId: "unexpectedCall",245                type: "CallExpression"246            }]247        },248        {249            code: "var foo = Boolean() ? bar() : baz()",250            output: "var foo = false ? bar() : baz()",251            errors: [{252                messageId: "unexpectedCall",253                type: "CallExpression"254            }]255        },256        {257            code: "if (Boolean()) { foo() }",258            output: "if (false) { foo() }",259            errors: [{260                messageId: "unexpectedCall",261                type: "CallExpression"262            }]263        },264        {265            code: "while (Boolean()) { foo() }",266            output: "while (false) { foo() }",267            errors: [{268                messageId: "unexpectedCall",269                type: "CallExpression"270            }]271        },272        // Adjacent tokens tests273        {274            code: "function *foo() { yield!!a ? b : c }",275            output: "function *foo() { yield a ? b : c }",276            parserOptions: { ecmaVersion: 2015 },277            errors: [{278                messageId: "unexpectedNegation",279                type: "UnaryExpression"280            }]281        },282        {283            code: "function *foo() { yield!! a ? b : c }",284            output: "function *foo() { yield a ? b : c }",285            parserOptions: { ecmaVersion: 2015 },286            errors: [{287                messageId: "unexpectedNegation",288                type: "UnaryExpression"289            }]290        },291        {292            code: "function *foo() { yield! !a ? b : c }",293            output: "function *foo() { yield a ? b : c }",294            parserOptions: { ecmaVersion: 2015 },295            errors: [{296                messageId: "unexpectedNegation",297                type: "UnaryExpression"298            }]299        },300        {301            code: "function *foo() { yield !!a ? b : c }",302            output: "function *foo() { yield a ? b : c }",303            parserOptions: { ecmaVersion: 2015 },304            errors: [{305                messageId: "unexpectedNegation",306                type: "UnaryExpression"307            }]308        },309        {310            code: "function *foo() { yield(!!a) ? b : c }",311            output: "function *foo() { yield(a) ? b : c }",312            parserOptions: { ecmaVersion: 2015 },313            errors: [{314                messageId: "unexpectedNegation",315                type: "UnaryExpression"316            }]317        },318        {319            code: "function *foo() { yield/**/!!a ? b : c }",320            output: "function *foo() { yield/**/a ? b : c }",321            parserOptions: { ecmaVersion: 2015 },322            errors: [{323                messageId: "unexpectedNegation",324                type: "UnaryExpression"325            }]326        },327        {328            code: "x=!!a ? b : c ",329            output: "x=a ? b : c ",330            errors: [{331                messageId: "unexpectedNegation",332                type: "UnaryExpression"333            }]334        },335        {336            code: "void!Boolean()",337            output: "void true",338            errors: [{339                messageId: "unexpectedCall",340                type: "CallExpression"341            }]342        },343        {344            code: "void! Boolean()",345            output: "void true",346            errors: [{347                messageId: "unexpectedCall",348                type: "CallExpression"349            }]350        },351        {352            code: "typeof!Boolean()",353            output: "typeof true",354            errors: [{355                messageId: "unexpectedCall",356                type: "CallExpression"357            }]358        },359        {360            code: "(!Boolean())",361            output: "(true)",362            errors: [{363                messageId: "unexpectedCall",364                type: "CallExpression"365            }]366        },367        {368            code: "+!Boolean()",369            output: "+true",370            errors: [{371                messageId: "unexpectedCall",372                type: "CallExpression"373            }]374        },375        {376            code: "void !Boolean()",377            output: "void true",378            errors: [{379                messageId: "unexpectedCall",380                type: "CallExpression"381            }]382        },383        {384            code: "void(!Boolean())",385            output: "void(true)",386            errors: [{387                messageId: "unexpectedCall",388                type: "CallExpression"389            }]390        },391        {392            code: "void/**/!Boolean()",393            output: "void/**/true",394            errors: [{395                messageId: "unexpectedCall",396                type: "CallExpression"397            }]398        },399        // Comments tests400        {401            code: "!/**/!!foo",402            output: "!/**/foo",403            errors: [{404                messageId: "unexpectedNegation",405                type: "UnaryExpression"406            }]407        },408        {409            code: "!!/**/!foo",410            output: null,411            errors: [{412                messageId: "unexpectedNegation",413                type: "UnaryExpression"414            }]415        },416        {417            code: "!!!/**/foo",418            output: null,419            errors: [{420                messageId: "unexpectedNegation",421                type: "UnaryExpression"422            }]423        },424        {425            code: "!!!foo/**/",426            output: "!foo/**/",427            errors: [{428                messageId: "unexpectedNegation",429                type: "UnaryExpression"430            }]431        },432        {433            code: "if(!/**/!foo);",434            output: null,435            errors: [{436                messageId: "unexpectedNegation",437                type: "UnaryExpression"438            }]439        },440        {441            code: "(!!/**/foo ? 1 : 2)",442            output: null,443            errors: [{444                messageId: "unexpectedNegation",445                type: "UnaryExpression"446            }]447        },448        {449            code: "!/**/Boolean(foo)",450            output: "!/**/foo",451            errors: [{452                messageId: "unexpectedCall",453                type: "CallExpression"454            }]455        },456        {457            code: "!Boolean/**/(foo)",458            output: null,459            errors: [{460                messageId: "unexpectedCall",461                type: "CallExpression"462            }]463        },464        {465            code: "!Boolean(/**/foo)",466            output: null,467            errors: [{468                messageId: "unexpectedCall",469                type: "CallExpression"470            }]471        },472        {473            code: "!Boolean(foo/**/)",474            output: null,475            errors: [{476                messageId: "unexpectedCall",477                type: "CallExpression"478            }]479        },480        {481            code: "!Boolean(foo)/**/",482            output: "!foo/**/",483            errors: [{484                messageId: "unexpectedCall",485                type: "CallExpression"486            }]487        },488        {489            code: "if(Boolean/**/(foo));",490            output: null,491            errors: [{492                messageId: "unexpectedCall",493                type: "CallExpression"494            }]495        },496        {497            code: "(Boolean(foo/**/) ? 1 : 2)",498            output: null,499            errors: [{500                messageId: "unexpectedCall",501                type: "CallExpression"502            }]503        },504        {505            code: "/**/!Boolean()",506            output: "/**/true",507            errors: [{508                messageId: "unexpectedCall",509                type: "CallExpression"510            }]511        },512        {513            code: "!/**/Boolean()",514            output: null,515            errors: [{516                messageId: "unexpectedCall",517                type: "CallExpression"518            }]519        },520        {521            code: "!Boolean/**/()",522            output: null,523            errors: [{524                messageId: "unexpectedCall",525                type: "CallExpression"526            }]527        },528        {529            code: "!Boolean(/**/)",530            output: null,531            errors: [{532                messageId: "unexpectedCall",533                type: "CallExpression"534            }]535        },536        {537            code: "!Boolean()/**/",538            output: "true/**/",539            errors: [{540                messageId: "unexpectedCall",541                type: "CallExpression"542            }]543        },544        {545            code: "if(!/**/Boolean());",546            output: null,547            errors: [{548                messageId: "unexpectedCall",549                type: "CallExpression"550            }]551        },552        {553            code: "(!Boolean(/**/) ? 1 : 2)",554            output: null,555            errors: [{556                messageId: "unexpectedCall",557                type: "CallExpression"558            }]559        },560        {561            code: "if(/**/Boolean());",562            output: "if(/**/false);",563            errors: [{564                messageId: "unexpectedCall",565                type: "CallExpression"566            }]567        },568        {569            code: "if(Boolean/**/());",570            output: null,571            errors: [{572                messageId: "unexpectedCall",573                type: "CallExpression"574            }]575        },576        {577            code: "if(Boolean(/**/));",578            output: null,579            errors: [{580                messageId: "unexpectedCall",581                type: "CallExpression"582            }]583        },584        {585            code: "if(Boolean()/**/);",586            output: "if(false/**/);",587            errors: [{588                messageId: "unexpectedCall",589                type: "CallExpression"590            }]591        },592        {593            code: "(Boolean/**/() ? 1 : 2)",594            output: null,595            errors: [{596                messageId: "unexpectedCall",597                type: "CallExpression"598            }]599        }600    ]...mirror-object.js
Source:mirror-object.js  
1// Copyright 2012 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6//     * Redistributions of source code must retain the above copyright7//       notice, this list of conditions and the following disclaimer.8//     * Redistributions in binary form must reproduce the above9//       copyright notice, this list of conditions and the following10//       disclaimer in the documentation and/or other materials provided11//       with the distribution.12//     * Neither the name of Google Inc. nor the names of its13//       contributors may be used to endorse or promote products derived14//       from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27// Flags: --expose-debug-as debug28// Test the mirror object for objects29function MirrorRefCache(json_refs) {30  var tmp = eval('(' + json_refs + ')');31  this.refs_ = [];32  for (var i = 0; i < tmp.length; i++) {33    this.refs_[tmp[i].handle] = tmp[i];34  }35}36MirrorRefCache.prototype.lookup = function(handle) {37  return this.refs_[handle];38};39function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {40  // Create mirror and JSON representation.41  var mirror = debug.MakeMirror(obj);42  var serializer = debug.MakeMirrorSerializer();43  var json = JSON.stringify(serializer.serializeValue(mirror));44  var refs = new MirrorRefCache(45      JSON.stringify(serializer.serializeReferencedObjects()));46  // Check the mirror hierachy.47  assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierarchy');48  assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierarchy');49  assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierarchy');50  // Check the mirror properties.51  assertTrue(mirror.isObject(), 'Unexpected mirror');52  assertEquals('object', mirror.type(), 'Unexpected mirror type');53  assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');54  assertEquals(cls_name, mirror.className(), 'Unexpected mirror class name');55  assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpected mirror hierarchy');56  assertEquals(ctor_name, mirror.constructorFunction().name(), 'Unexpected constructor function name');57  assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hierarchy');58  assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirror hierarchy');59  assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected');60  assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected');61  var names = mirror.propertyNames();62  var properties = mirror.properties();63  assertEquals(names.length, properties.length);64  for (var i = 0; i < properties.length; i++) {65    assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierarchy');66    assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierarchy');67    assertEquals('property', properties[i].type(), 'Unexpected mirror type');68    assertEquals(names[i], properties[i].name(), 'Unexpected property name');69  }70  var internalProperties = mirror.internalProperties();71  for (var i = 0; i < internalProperties.length; i++) {72    assertTrue(internalProperties[i] instanceof debug.Mirror, 'Unexpected mirror hierarchy');73    assertTrue(internalProperties[i] instanceof debug.InternalPropertyMirror, 'Unexpected mirror hierarchy');74    assertEquals('internalProperty', internalProperties[i].type(), 'Unexpected mirror type');75  }76  for (var p in obj) {77    var property_mirror = mirror.property(p);78    assertTrue(property_mirror instanceof debug.PropertyMirror);79    assertEquals(p, property_mirror.name());80    // If the object has some special properties don't test for these.81    if (!hasSpecialProperties) {82      assertEquals(0, property_mirror.attributes(), property_mirror.name());83      assertFalse(property_mirror.isReadOnly());84      assertTrue(property_mirror.isEnum());85      assertTrue(property_mirror.canDelete());86    }87  }88  // Parse JSON representation and check.89  var fromJSON = eval('(' + json + ')');90  assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');91  assertEquals(cls_name, fromJSON.className, 'Unexpected mirror class name in JSON');92  assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');93  assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');94  assertEquals(ctor_name, refs.lookup(fromJSON.constructorFunction.ref).name, 'Unexpected constructor function name in JSON');95  assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpected proto object handle in JSON');96  assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref).type, 'Unexpected proto object type in JSON');97  assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref, 'Unexpected prototype object handle in JSON');98  assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeObject.ref).type, 'Unexpected prototype object type in JSON');99  assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');100  assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expected in JSON');101  // Check that the serialization contains all properties.102  assertEquals(names.length, fromJSON.properties.length, 'Some properties missing in JSON');103  for (var i = 0; i < fromJSON.properties.length; i++) {104    var name = fromJSON.properties[i].name;105    if (typeof name == 'undefined') name = fromJSON.properties[i].index;106    var found = false;107    for (var j = 0; j < names.length; j++) {108      if (names[j] == name) {109        // Check that serialized handle is correct.110        assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref, 'Unexpected serialized handle');111        // Check that serialized name is correct.112        assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpected serialized name');113        // If property type is normal property type is not serialized.114        if (properties[i].propertyType() != debug.PropertyType.Normal) {115          assertEquals(properties[i].propertyType(), fromJSON.properties[i].propertyType, 'Unexpected serialized property type');116        } else {117          assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined', 'Unexpected serialized property type');118        }119        // If there are no attributes attributes are not serialized.120        if (properties[i].attributes() != debug.PropertyAttribute.None) {121          assertEquals(properties[i].attributes(), fromJSON.properties[i].attributes, 'Unexpected serialized attributes');122        } else {123          assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes');124        }125        // Lookup the serialized object from the handle reference.126        var o = refs.lookup(fromJSON.properties[i].ref);127        assertTrue(o != void 0, 'Referenced object is not serialized');128        assertEquals(properties[i].value().type(), o.type, 'Unexpected serialized property type for ' + name);129        if (properties[i].value().isPrimitive()) {130          if (properties[i].value().type() == "null" ||131              properties[i].value().type() == "undefined") {132            // Null and undefined has no value property.133            assertFalse("value" in o, 'Unexpected value property for ' + name);134          } else if (properties[i].value().type() == "number" &&135                     !isFinite(properties[i].value().value())) {136            assertEquals(String(properties[i].value().value()), o.value,137                         'Unexpected serialized property value for ' + name);138          } else {139            assertEquals(properties[i].value().value(), o.value, 'Unexpected serialized property value for ' + name);140          }141        } else if (properties[i].value().isFunction()) {142          assertEquals(properties[i].value().source(), o.source, 'Unexpected serialized property value for ' + name);143        }144        found = true;145      }146    }147    assertTrue(found, '"' + name + '" not found (' + json + ')');148  }149}150function Point(x,y) {151  this.x_ = x;152  this.y_ = y;153}154// Test a number of different objects.155testObjectMirror({}, 'Object', 'Object');156testObjectMirror({'a':1,'b':2}, 'Object', 'Object');157testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y);}}, 'Object', 'Object');158testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point');159testObjectMirror(this, 'global', '', true);  // Global object has special properties160testObjectMirror(this.__proto__, 'Object', '');161testObjectMirror([], 'Array', 'Array');162testObjectMirror([1,2], 'Array', 'Array');163testObjectMirror(Object(17), 'Number', 'Number');164// Test circular references.165o = {};166o.o = o;167testObjectMirror(o, 'Object', 'Object');168// Test that non enumerable properties are part of the mirror169global_mirror = debug.MakeMirror(this);170assertEquals('property', global_mirror.property("Math").type());171assertFalse(global_mirror.property("Math").isEnum(), "Math is enumerable" + global_mirror.property("Math").attributes());172math_mirror = global_mirror.property("Math").value();173assertEquals('property', math_mirror.property("E").type());174assertFalse(math_mirror.property("E").isEnum(), "Math.E is enumerable");175assertTrue(math_mirror.property("E").isReadOnly());176assertFalse(math_mirror.property("E").canDelete());177// Test objects with JavaScript accessors.178o = {}179o.__defineGetter__('a', function(){return 'a';});180o.__defineSetter__('b', function(){});181o.__defineGetter__('c', function(){throw 'c';});182o.__defineSetter__('c', function(){throw 'c';});183testObjectMirror(o, 'Object', 'Object');184mirror = debug.MakeMirror(o);185// a has getter but no setter.186assertTrue(mirror.property('a').hasGetter());187assertFalse(mirror.property('a').hasSetter());188assertEquals(debug.PropertyType.Callbacks, mirror.property('a').propertyType());189assertEquals('function', mirror.property('a').getter().type());190assertEquals('undefined', mirror.property('a').setter().type());191assertEquals('function (){return \'a\';}', mirror.property('a').getter().source());192// b has setter but no getter.193assertFalse(mirror.property('b').hasGetter());194assertTrue(mirror.property('b').hasSetter());195assertEquals(debug.PropertyType.Callbacks, mirror.property('b').propertyType());196assertEquals('undefined', mirror.property('b').getter().type());197assertEquals('function', mirror.property('b').setter().type());198assertEquals('function (){}', mirror.property('b').setter().source());199assertFalse(mirror.property('b').isException());200// c has both getter and setter. The getter throws an exception.201assertTrue(mirror.property('c').hasGetter());202assertTrue(mirror.property('c').hasSetter());203assertEquals(debug.PropertyType.Callbacks, mirror.property('c').propertyType());204assertEquals('function', mirror.property('c').getter().type());205assertEquals('function', mirror.property('c').setter().type());206assertEquals('function (){throw \'c\';}', mirror.property('c').getter().source());207assertEquals('function (){throw \'c\';}', mirror.property('c').setter().source());208// Test objects with native accessors.209mirror = debug.MakeMirror(new String('abc'));210assertTrue(mirror instanceof debug.ObjectMirror);211assertFalse(mirror.property('length').hasGetter());212assertFalse(mirror.property('length').hasSetter());213assertTrue(mirror.property('length').isNative());214assertEquals('a', mirror.property(0).value().value());215assertEquals('b', mirror.property(1).value().value());216assertEquals('c', mirror.property(2).value().value());217// Test value wrapper internal properties.218mirror = debug.MakeMirror(Object("Capybara"));219var ip = mirror.internalProperties();220assertEquals(1, ip.length);221assertEquals("[[PrimitiveValue]]", ip[0].name());222assertEquals("string", ip[0].value().type());223assertEquals("Capybara", ip[0].value().value());224// Test bound function internal properties.225mirror = debug.MakeMirror(Number.bind(Array, 2));226ip = mirror.internalProperties();227assertEquals(3, ip.length);228var property_map = {};229for (var i = 0; i < ip.length; i++) {230  property_map[ip[i].name()] = ip[i];231}232assertTrue("[[BoundThis]]" in property_map);233assertEquals("function", property_map["[[BoundThis]]"].value().type());234assertEquals(Array, property_map["[[BoundThis]]"].value().value());235assertTrue("[[TargetFunction]]" in property_map);236assertEquals("function", property_map["[[TargetFunction]]"].value().type());237assertEquals(Number, property_map["[[TargetFunction]]"].value().value());238assertTrue("[[BoundArgs]]" in property_map);239assertEquals("object", property_map["[[BoundArgs]]"].value().type());...no-dupe-else-if.js
Source:no-dupe-else-if.js  
1/**2 * @fileoverview Tests for the no-dupe-else-if rule3 * @author Milos Djermanovic4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/no-dupe-else-if");10const { RuleTester } = require("../../../lib/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("no-dupe-else-if", rule, {16    valid: [17        // different test conditions18        "if (a) {} else if (b) {}",19        "if (a); else if (b); else if (c);",20        "if (true) {} else if (false) {} else {}",21        "if (1) {} else if (2) {}",22        "if (f) {} else if (f()) {}",23        "if (f(a)) {} else if (g(a)) {}",24        "if (f(a)) {} else if (f(b)) {}",25        "if (a === 1) {} else if (a === 2) {}",26        "if (a === 1) {} else if (b === 1) {}",27        // not an if-else-if chain28        "if (a) {}",29        "if (a);",30        "if (a) {} else {}",31        "if (a) if (a) {}",32        "if (a) if (a);",33        "if (a) { if (a) {} }",34        "if (a) {} else { if (a) {} }",35        "if (a) {} if (a) {}",36        "if (a); if (a);",37        "while (a) if (a);",38        "if (a); else a ? a : a;",39        // not same conditions in the chain40        "if (a) { if (b) {} } else if (b) {}",41        "if (a) if (b); else if (a);",42        // not equal tokens43        "if (a) {} else if (!!a) {}",44        "if (a === 1) {} else if (a === (1)) {}",45        // more complex valid chains (may contain redundant subconditions, but the branch can be executed)46        "if (a || b) {} else if (c || d) {}",47        "if (a || b) {} else if (a || c) {}",48        "if (a) {} else if (a || b) {}",49        "if (a) {} else if (b) {} else if (a || b || c) {}",50        "if (a && b) {} else if (a) {} else if (b) {}",51        "if (a && b) {} else if (b && c) {} else if (a && c) {}",52        "if (a && b) {} else if (b || c) {}",53        "if (a) {} else if (b && (a || c)) {}",54        "if (a) {} else if (b && (c || d && a)) {}",55        "if (a && b && c) {} else if (a && b && (c || d)) {}"56    ],57    invalid: [58        // basic tests59        {60            code: "if (a) {} else if (a) {}",61            errors: [{ messageId: "unexpected", type: "Identifier", column: 20 }]62        },63        {64            code: "if (a); else if (a);",65            errors: [{ messageId: "unexpected", type: "Identifier", column: 18 }]66        },67        {68            code: "if (a) {} else if (a) {} else {}",69            errors: [{ messageId: "unexpected", type: "Identifier", column: 20 }]70        },71        {72            code: "if (a) {} else if (b) {} else if (a) {} else if (c) {}",73            errors: [{ messageId: "unexpected", type: "Identifier", column: 35 }]74        },75        {76            code: "if (a) {} else if (b) {} else if (a) {}",77            errors: [{ messageId: "unexpected", type: "Identifier", column: 35 }]78        },79        {80            code: "if (a) {} else if (b) {} else if (c) {} else if (a) {}",81            errors: [{ messageId: "unexpected", type: "Identifier", column: 50 }]82        },83        {84            code: "if (a) {} else if (b) {} else if (b) {}",85            errors: [{ messageId: "unexpected", type: "Identifier", column: 35 }]86        },87        {88            code: "if (a) {} else if (b) {} else if (b) {} else {}",89            errors: [{ messageId: "unexpected", type: "Identifier", column: 35 }]90        },91        {92            code: "if (a) {} else if (b) {} else if (c) {} else if (b) {}",93            errors: [{ messageId: "unexpected", type: "Identifier", column: 50 }]94        },95        {96            code: "if (a); else if (b); else if (c); else if (b); else if (d); else;",97            errors: [{ messageId: "unexpected", type: "Identifier", column: 44 }]98        },99        {100            code: "if (a); else if (b); else if (c); else if (d); else if (b); else if (e);",101            errors: [{ messageId: "unexpected", type: "Identifier", column: 57 }]102        },103        // multiple duplicates of the same condition104        {105            code: "if (a) {} else if (a) {} else if (a) {}",106            errors: [107                { messageId: "unexpected", type: "Identifier", column: 20 },108                { messageId: "unexpected", type: "Identifier", column: 35 }109            ]110        },111        // multiple duplicates of different conditions112        {113            code: "if (a) {} else if (b) {} else if (a) {} else if (b) {} else if (a) {}",114            errors: [115                { messageId: "unexpected", type: "Identifier", column: 35 },116                { messageId: "unexpected", type: "Identifier", column: 50 },117                { messageId: "unexpected", type: "Identifier", column: 65 }118            ]119        },120        // inner if statements do not affect chain121        {122            code: "if (a) { if (b) {} } else if (a) {}",123            errors: [{ messageId: "unexpected", type: "Identifier", column: 31 }]124        },125        // various kinds of test conditions126        {127            code: "if (a === 1) {} else if (a === 1) {}",128            errors: [{ messageId: "unexpected", type: "BinaryExpression", column: 26 }]129        },130        {131            code: "if (1 < a) {} else if (1 < a) {}",132            errors: [{ messageId: "unexpected", type: "BinaryExpression", column: 24 }]133        },134        {135            code: "if (true) {} else if (true) {}",136            errors: [{ messageId: "unexpected", type: "Literal", column: 23 }]137        },138        {139            code: "if (a && b) {} else if (a && b) {}",140            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]141        },142        {143            code: "if (a && b || c)  {} else if (a && b || c) {}",144            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 31 }]145        },146        {147            code: "if (f(a)) {} else if (f(a)) {}",148            errors: [{ messageId: "unexpected", type: "CallExpression", column: 23 }]149        },150        // spaces and comments do not affect comparison151        {152            code: "if (a === 1) {} else if (a===1) {}",153            errors: [{ messageId: "unexpected", type: "BinaryExpression", column: 26 }]154        },155        {156            code: "if (a === 1) {} else if (a === /* comment */ 1) {}",157            errors: [{ messageId: "unexpected", type: "BinaryExpression", column: 26 }]158        },159        // extra parens around the whole test condition do not affect comparison160        {161            code: "if (a === 1) {} else if ((a === 1)) {}",162            errors: [{ messageId: "unexpected", type: "BinaryExpression", column: 27 }]163        },164        // more complex errors with `||` and `&&`165        {166            code: "if (a || b) {} else if (a) {}",167            errors: [{ messageId: "unexpected", type: "Identifier", column: 25 }]168        },169        {170            code: "if (a || b) {} else if (a) {} else if (b) {}",171            errors: [172                { messageId: "unexpected", type: "Identifier", column: 25 },173                { messageId: "unexpected", type: "Identifier", column: 40 }174            ]175        },176        {177            code: "if (a || b) {} else if (b || a) {}",178            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]179        },180        {181            code: "if (a) {} else if (b) {} else if (a || b) {}",182            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 35 }]183        },184        {185            code: "if (a || b) {} else if (c || d) {} else if (a || d) {}",186            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 45 }]187        },188        {189            code: "if ((a === b && fn(c)) || d) {} else if (fn(c) && a === b) {}",190            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 42 }]191        },192        {193            code: "if (a) {} else if (a && b) {}",194            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 20 }]195        },196        {197            code: "if (a && b) {} else if (b && a) {}",198            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]199        },200        {201            code: "if (a && b) {} else if (a && b && c) {}",202            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]203        },204        {205            code: "if (a || c) {} else if (a && b || c) {}",206            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]207        },208        {209            code: "if (a) {} else if (b) {} else if (c && a || b) {}",210            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 35 }]211        },212        {213            code: "if (a) {} else if (b) {} else if (c && (a || b)) {}",214            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 35 }]215        },216        {217            code: "if (a) {} else if (b && c) {} else if (d && (a || e && c && b)) {}",218            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 40 }]219        },220        {221            code: "if (a || b && c) {} else if (b && c && d) {}",222            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 30 }]223        },224        {225            code: "if (a || b) {} else if (b && c) {}",226            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]227        },228        {229            code: "if (a) {} else if (b) {} else if ((a || b) && c) {}",230            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 35 }]231        },232        {233            code: "if ((a && (b || c)) || d) {} else if ((c || b) && e && a) {}",234            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 39 }]235        },236        {237            code: "if (a && b || b && c) {} else if (a && b && c) {}",238            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 35 }]239        },240        {241            code: "if (a) {} else if (b && c) {} else if (d && (c && e && b || a)) {}",242            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 40 }]243        },244        {245            code: "if (a || (b && (c || d))) {} else if ((d || c) && b) {}",246            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 39 }]247        },248        {249            code: "if (a || b) {} else if ((b || a) && c) {}",250            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]251        },252        {253            code: "if (a || b) {} else if (c) {} else if (d) {} else if (b && (a || c)) {}",254            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 55 }]255        },256        {257            code: "if (a || b || c) {} else if (a || (b && d) || (c && e)) {}",258            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 30 }]259        },260        {261            code: "if (a || (b || c)) {} else if (a || (b && c)) {}",262            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 32 }]263        },264        {265            code: "if (a || b) {} else if (c) {} else if (d) {} else if ((a || c) && (b || d)) {}",266            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 55 }]267        },268        {269            code: "if (a) {} else if (b) {} else if (c && (a || d && b)) {}",270            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 35 }]271        },272        {273            code: "if (a) {} else if (a || a) {}",274            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 20 }]275        },276        {277            code: "if (a || a) {} else if (a || a) {}",278            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]279        },280        {281            code: "if (a || a) {} else if (a) {}",282            errors: [{ messageId: "unexpected", type: "Identifier", column: 25 }]283        },284        {285            code: "if (a) {} else if (a && a) {}",286            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 20 }]287        },288        {289            code: "if (a && a) {} else if (a && a) {}",290            errors: [{ messageId: "unexpected", type: "LogicalExpression", column: 25 }]291        },292        {293            code: "if (a && a) {} else if (a) {}",294            errors: [{ messageId: "unexpected", type: "Identifier", column: 25 }]295        }296    ]...no-constant-condition.js
Source:no-constant-condition.js  
1/**2 * @fileoverview Tests for no-constant-condition rule.3 * @author Christian Schulz <http://rndm.de>4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/no-constant-condition"),10    { RuleTester } = require("../../../lib/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });15ruleTester.run("no-constant-condition", rule, {16    valid: [17        "if(a);",18        "if(a == 0);",19        "if(a = f());",20        "if(1, a);",21        "if ('every' in []);",22        "while(~!a);",23        "while(a = b);",24        "for(;x < 10;);",25        "for(;;);",26        "do{ }while(x)",27        "q > 0 ? 1 : 2;",28        "while(x += 3) {}",29        // #5228, typeof conditions30        "if(typeof x === 'undefined'){}",31        "if(a === 'str' && typeof b){}",32        "typeof a == typeof b",33        "typeof 'a' === 'string'|| typeof b === 'string'",34        // #5726, void conditions35        "if (void a || a);",36        "if (a || void a);",37        // #569338        "if(xyz === 'str1' && abc==='str2'){}",39        "if(xyz === 'str1' || abc==='str2'){}",40        "if(xyz === 'str1' || abc==='str2' && pqr === 5){}",41        "if(typeof abc === 'string' && abc==='str2'){}",42        "if(false || abc==='str'){}",43        "if(true && abc==='str'){}",44        "if(typeof 'str' && abc==='str'){}",45        "if(abc==='str' || false || def ==='str'){}",46        "if(true && abc==='str' || def ==='str'){}",47        "if(true && typeof abc==='string'){}",48        // #11181, string literals49        "if('str' || a){}",50        "if('str1' && a){}",51        "if(a && 'str'){}",52        "if('str' || abc==='str'){}",53        // #1130654        "if ((foo || 'bar') === 'baz') {}",55        "if ((foo || 'bar') !== 'baz') {}",56        "if ((foo || 'bar') == 'baz') {}",57        "if ((foo || 'bar') != 'baz') {}",58        "if ((foo || 233) > 666) {}",59        "if ((foo || 233) < 666) {}",60        "if ((foo || 233) >= 666) {}",61        "if ((foo || 233) <= 666) {}",62        "if ((key || 'k') in obj) {}",63        "if ((foo || {}) instanceof obj) {}",64        // { checkLoops: false }65        { code: "while(true);", options: [{ checkLoops: false }] },66        { code: "for(;true;);", options: [{ checkLoops: false }] },67        { code: "do{}while(true)", options: [{ checkLoops: false }] },68        "function* foo(){while(true){yield 'foo';}}",69        "function* foo(){for(;true;){yield 'foo';}}",70        "function* foo(){do{yield 'foo';}while(true)}",71        "function* foo(){while (true) { while(true) {yield;}}}",72        "function* foo() {for (; yield; ) {}}",73        "function* foo() {for (; ; yield) {}}",74        "function* foo() {while (true) {function* foo() {yield;}yield;}}",75        "function* foo() { for (let x = yield; x < 10; x++) {yield;}yield;}",76        "function* foo() { for (let x = yield; ; x++) { yield; }}"77    ],78    invalid: [79        { code: "for(;true;);", errors: [{ messageId: "unexpected", type: "Literal" }] },80        { code: "do{}while(true)", errors: [{ messageId: "unexpected", type: "Literal" }] },81        { code: "do{}while(t = -2)", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] },82        { code: "true ? 1 : 2;", errors: [{ messageId: "unexpected", type: "Literal" }] },83        { code: "q = 0 ? 1 : 2;", errors: [{ messageId: "unexpected", type: "Literal" }] },84        { code: "(q = 0) ? 1 : 2;", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] },85        { code: "if(-2);", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] },86        { code: "if(true);", errors: [{ messageId: "unexpected", type: "Literal" }] },87        { code: "if({});", errors: [{ messageId: "unexpected", type: "ObjectExpression" }] },88        { code: "if(0 < 1);", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] },89        { code: "if(0 || 1);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },90        { code: "if(a, 1);", errors: [{ messageId: "unexpected", type: "SequenceExpression" }] },91        { code: "while([]);", errors: [{ messageId: "unexpected", type: "ArrayExpression" }] },92        { code: "while(~!0);", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] },93        { code: "while(x = 1);", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] },94        { code: "while(function(){});", errors: [{ messageId: "unexpected", type: "FunctionExpression" }] },95        { code: "while(true);", errors: [{ messageId: "unexpected", type: "Literal" }] },96        { code: "while(() => {});", errors: [{ messageId: "unexpected", type: "ArrowFunctionExpression" }] },97        // #5228 , typeof conditions98        { code: "if(typeof x){}", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] },99        { code: "if(typeof 'abc' === 'string'){}", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] },100        { code: "if(a = typeof b){}", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] },101        { code: "if(a, typeof b){}", errors: [{ messageId: "unexpected", type: "SequenceExpression" }] },102        { code: "if(typeof 'a' == 'string' || typeof 'b' == 'string'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },103        { code: "while(typeof x){}", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] },104        // #5726, void conditions105        { code: "if(1 || void x);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },106        { code: "if(void x);", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] },107        { code: "if(y = void x);", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] },108        { code: "if(x, void x);", errors: [{ messageId: "unexpected", type: "SequenceExpression" }] },109        { code: "if(void x === void y);", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] },110        { code: "if(void x && a);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },111        { code: "if(a && void x);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },112        // #5693113        { code: "if(false && abc==='str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },114        { code: "if(true || abc==='str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },115        { code: "if(abc==='str' || true){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },116        { code: "if(abc==='str' || true || def ==='str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },117        { code: "if(false || true){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },118        { code: "if(typeof abc==='str' || true){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },119        // #11181, string literals120        { code: "if('str1' || 'str2'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },121        { code: "if('str1' && 'str2'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },122        { code: "if(abc==='str' || 'str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },123        { code: "if(a || 'str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] },124        {125            code: "function* foo(){while(true){} yield 'foo';}",126            errors: [{ messageId: "unexpected", type: "Literal" }]127        },128        {129            code: "function* foo(){while(true){if (true) {yield 'foo';}}}",130            errors: [{ messageId: "unexpected", type: "Literal" }]131        },132        {133            code: "function* foo(){while(true){yield 'foo';} while(true) {}}",134            errors: [{ messageId: "unexpected", type: "Literal" }]135        },136        {137            code: "var a = function* foo(){while(true){} yield 'foo';}",138            errors: [{ messageId: "unexpected", type: "Literal" }]139        },140        {141            code: "while (true) { function* foo() {yield;}}",142            errors: [{ messageId: "unexpected", type: "Literal" }]143        },144        {145            code: "function* foo(){if (true) {yield 'foo';}}",146            errors: [{ messageId: "unexpected", type: "Literal" }]147        },148        {149            code: "function* foo() {for (let foo = yield; true;) {}}",150            errors: [{ messageId: "unexpected", type: "Literal" }]151        },152        {153            code: "function* foo() {for (foo = yield; true;) {}}",154            errors: [{ messageId: "unexpected", type: "Literal" }]155        },156        {157            code: "function foo() {while (true) {function* bar() {while (true) {yield;}}}}",158            errors: [{ messageId: "unexpected", type: "Literal" }]159        },160        {161            code: "function foo() {while (true) {const bar = function*() {while (true) {yield;}}}}",162            errors: [{ messageId: "unexpected", type: "Literal" }]163        },164        {165            code: "function* foo() { for (let foo = 1 + 2 + 3 + (yield); true; baz) {}}",166            errors: [{ messageId: "unexpected", type: "Literal" }]167        }168    ]...no-labels.js
Source:no-labels.js  
1/**2 * @fileoverview Disallow Labeled Statements3 * @author Nicholas C. Zakas4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/no-labels"),10    { RuleTester } = require("../../../lib/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("no-labels", rule, {16    valid: [17        "var f = { label: foo ()}",18        "while (true) {}",19        "while (true) { break; }",20        "while (true) { continue; }",21        // {allowLoop: true} option.22        { code: "A: while (a) { break A; }", options: [{ allowLoop: true }] },23        { code: "A: do { if (b) { break A; } } while (a);", options: [{ allowLoop: true }] },24        { code: "A: for (var a in obj) { for (;;) { switch (a) { case 0: continue A; } } }", options: [{ allowLoop: true }] },25        // {allowSwitch: true} option.26        { code: "A: switch (a) { case 0: break A; }", options: [{ allowSwitch: true }] }27    ],28    invalid: [29        {30            code: "label: while(true) {}",31            errors: [{32                message: "Unexpected labeled statement.",33                type: "LabeledStatement"34            }]35        },36        {37            code: "label: while (true) { break label; }",38            errors: [{39                message: "Unexpected labeled statement.",40                type: "LabeledStatement"41            }, {42                message: "Unexpected label in break statement.",43                type: "BreakStatement"44            }]45        },46        {47            code: "label: while (true) { continue label; }",48            errors: [{49                message: "Unexpected labeled statement.",50                type: "LabeledStatement"51            }, {52                message: "Unexpected label in continue statement.",53                type: "ContinueStatement"54            }]55        },56        {57            code: "A: var foo = 0;",58            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }]59        },60        {61            code: "A: break A;",62            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]63        },64        {65            code: "A: { if (foo()) { break A; } bar(); };",66            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]67        },68        {69            code: "A: if (a) { if (foo()) { break A; } bar(); };",70            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]71        },72        {73            code: "A: switch (a) { case 0: break A; default: break; };",74            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]75        },76        {77            code: "A: switch (a) { case 0: B: { break A; } default: break; };",78            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]79        },80        // {allowLoop: true} option.81        {82            code: "A: var foo = 0;",83            options: [{ allowLoop: true }],84            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }]85        },86        {87            code: "A: break A;",88            options: [{ allowLoop: true }],89            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]90        },91        {92            code: "A: { if (foo()) { break A; } bar(); };",93            options: [{ allowLoop: true }],94            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]95        },96        {97            code: "A: if (a) { if (foo()) { break A; } bar(); };",98            options: [{ allowLoop: true }],99            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]100        },101        {102            code: "A: switch (a) { case 0: break A; default: break; };",103            options: [{ allowLoop: true }],104            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]105        },106        // {allowSwitch: true} option.107        {108            code: "A: var foo = 0;",109            options: [{ allowSwitch: true }],110            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }]111        },112        {113            code: "A: break A;",114            options: [{ allowSwitch: true }],115            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]116        },117        {118            code: "A: { if (foo()) { break A; } bar(); };",119            options: [{ allowSwitch: true }],120            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]121        },122        {123            code: "A: if (a) { if (foo()) { break A; } bar(); };",124            options: [{ allowSwitch: true }],125            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]126        },127        {128            code: "A: while (a) { break A; }",129            options: [{ allowSwitch: true }],130            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]131        },132        {133            code: "A: do { if (b) { break A; } } while (a);",134            options: [{ allowSwitch: true }],135            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]136        },137        {138            code: "A: for (var a in obj) { for (;;) { switch (a) { case 0: break A; } } }",139            options: [{ allowSwitch: true }],140            errors: [{ message: "Unexpected labeled statement.", type: "LabeledStatement" }, { message: "Unexpected label in break statement.", type: "BreakStatement" }]141        }142    ]...no-mixed-operators.js
Source:no-mixed-operators.js  
1/**2 * @fileoverview Tests for no-mixed-operators rule.3 * @author Toru Nagashima4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/no-mixed-operators"),10    { RuleTester } = require("../../../lib/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("no-mixed-operators", rule, {16    valid: [17        "a && b && c && d",18        "a || b || c || d",19        "(a || b) && c && d",20        "a || (b && c && d)",21        "(a || b || c) && d",22        "a || b || (c && d)",23        "a + b + c + d",24        "a * b * c * d",25        "a == 0 && b == 1",26        "a == 0 || b == 1",27        {28            code: "(a == 0) && (b == 1)",29            options: [{ groups: [["&&", "=="]] }]30        },31        {32            code: "a + b - c * d / e",33            options: [{ groups: [["&&", "||"]] }]34        },35        "a + b - c",36        "a * b / c",37        {38            code: "a + b - c",39            options: [{ allowSamePrecedence: true }]40        },41        {42            code: "a * b / c",43            options: [{ allowSamePrecedence: true }]44        },45        {46            code: "(a || b) ? c : d",47            options: [{ groups: [["&&", "||", "?:"]] }]48        },49        {50            code: "a || (b ? c : d)",51            options: [{ groups: [["&&", "||", "?:"]] }]52        },53        "a || (b ? c : d)",54        "(a || b) ? c : d",55        "a || b ? c : d"56    ],57    invalid: [58        {59            code: "a && b || c",60            errors: [61                { column: 3, endColumn: 5, message: "Unexpected mix of '&&' and '||'." },62                { column: 8, endColumn: 10, message: "Unexpected mix of '&&' and '||'." }63            ]64        },65        {66            code: "a && b > 0 || c",67            options: [{ groups: [["&&", "||", ">"]] }],68            errors: [69                { column: 3, message: "Unexpected mix of '&&' and '||'." },70                { column: 3, message: "Unexpected mix of '&&' and '>'." },71                { column: 8, message: "Unexpected mix of '&&' and '>'." },72                { column: 12, message: "Unexpected mix of '&&' and '||'." }73            ]74        },75        {76            code: "a && b > 0 || c",77            options: [{ groups: [["&&", "||"]] }],78            errors: [79                { column: 3, message: "Unexpected mix of '&&' and '||'." },80                { column: 12, message: "Unexpected mix of '&&' and '||'." }81            ]82        },83        {84            code: "a && b + c - d / e || f",85            options: [{ groups: [["&&", "||"], ["+", "-", "*", "/"]] }],86            errors: [87                { column: 3, message: "Unexpected mix of '&&' and '||'." },88                { column: 12, message: "Unexpected mix of '-' and '/'." },89                { column: 16, message: "Unexpected mix of '-' and '/'." },90                { column: 20, message: "Unexpected mix of '&&' and '||'." }91            ]92        },93        {94            code: "a && b + c - d / e || f",95            options: [{ groups: [["&&", "||"], ["+", "-", "*", "/"]], allowSamePrecedence: true }],96            errors: [97                { column: 3, message: "Unexpected mix of '&&' and '||'." },98                { column: 12, message: "Unexpected mix of '-' and '/'." },99                { column: 16, message: "Unexpected mix of '-' and '/'." },100                { column: 20, message: "Unexpected mix of '&&' and '||'." }101            ]102        },103        {104            code: "a + b - c",105            options: [{ allowSamePrecedence: false }],106            errors: [107                { column: 3, endColumn: 4, message: "Unexpected mix of '+' and '-'." },108                { column: 7, endColumn: 8, message: "Unexpected mix of '+' and '-'." }109            ]110        },111        {112            code: "a * b / c",113            options: [{ allowSamePrecedence: false }],114            errors: [115                { column: 3, endColumn: 4, message: "Unexpected mix of '*' and '/'." },116                { column: 7, endColumn: 8, message: "Unexpected mix of '*' and '/'." }117            ]118        },119        {120            code: "a || b ? c : d",121            options: [{ groups: [["&&", "||", "?:"]] }],122            errors: [123                { column: 3, endColumn: 5, message: "Unexpected mix of '||' and '?:'." },124                { column: 8, endColumn: 9, message: "Unexpected mix of '||' and '?:'." }125            ]126        },127        {128            code: "a && b ? 1 : 2",129            options: [{ groups: [["&&", "||", "?:"]] }],130            errors: [131                { column: 3, endColumn: 5, message: "Unexpected mix of '&&' and '?:'." },132                { column: 8, endColumn: 9, message: "Unexpected mix of '&&' and '?:'." }133            ]134        },135        {136            code: "x ? a && b : 0",137            options: [{ groups: [["&&", "||", "?:"]] }],138            errors: [139                { column: 3, endColumn: 4, message: "Unexpected mix of '?:' and '&&'." },140                { column: 7, endColumn: 9, message: "Unexpected mix of '?:' and '&&'." }141            ]142        },143        {144            code: "x ? 0 : a && b",145            options: [{ groups: [["&&", "||", "?:"]] }],146            errors: [147                { column: 3, endColumn: 4, message: "Unexpected mix of '?:' and '&&'." },148                { column: 11, endColumn: 13, message: "Unexpected mix of '?:' and '&&'." }149            ]150        }151    ]...Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3  const browser = await chromium.launch();4  const context = await browser.newContext();5  const page = await context.newPage();6  await page.fill('input[aria-label="Search"]', 'Playwright');7  await page.press('input[aria-label="Search"]', 'Enter');8  await page.screenshot({ path: `example.png` });9  await browser.close();10})();11Error: Protocol error (Runtime.callFunctionOn): Target closed. at Object.callFunctionOn (/Users/username/Desktop/PlaywrightTest/node_modules/playwright/lib/cjs/pw_api.js:167:15) at async Object.waitForSelectorInPage (/Users/username/Desktop/PlaywrightTest/node_modules/playwright/lib/cjs/pw_api.js:104:27) at async Frame.waitForSelector (/Users/username/Desktop/PlaywrightTest/node_modules/playwright/lib/cjs/pw_api.js:105:27) at async Page.waitForSelector (/Users/username/Desktop/PlaywrightTest/node_modules/playwright/lib/cjs/pw_api.js:105:27) at async /Users/username/Desktop/PlaywrightTest/test.js:10:3Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3  const browser = await chromium.launch({ headless: false });4  const context = await browser.newContext();5  const page = await context.newPage();6  await page.waitForTimeout(5000);7  await page.screenshot({ path: `screenshot.png` });8  await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12  const browser = await chromium.launch({ headless: false });13  const context = await browser.newContext();14  const page = await context.newPage();15  await page.waitForTimeout(5000);16  await page.screenshot({ path: `screenshot.png` });17  await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21  const browser = await chromium.launch({ headless: false });22  const context = await browser.newContext();23  const page = await context.newPage();24  await page.waitForTimeout(5000);25  await page.screenshot({ path: `screenshot.png` });26  await browser.close();27})();28const { chromium } = require('playwright');29(async () => {30  const browser = await chromium.launch({ headless: false });31  const context = await browser.newContext();32  const page = await context.newPage();33  await page.waitForTimeout(5000);34  await page.screenshot({ path: `screenshot.png` });35  await browser.close();36})();37const { chromium } = require('playwright');38(async () => {39  const browser = await chromium.launch({ headless: false });40  const context = await browser.newContext();41  const page = await context.newPage();42  await page.waitForTimeout(5000);43  await page.screenshot({ path: `screenshot.png` });44  await browser.close();45})();Using AI Code Generation
1const { Playwright } = require('playwright');2const playwright = new Playwright();3const browser = await playwright.chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6await page.screenshot({ path: 'example.png' });7await browser.close();Using AI Code Generation
1const { chromium } = require('playwright');2const { expect } = require('chai');3(async () => {4  const browser = await chromium.launch();5  const page = await browser.newPage();6  await page.fill('input[name="q"]', 'Hello World');7  await page.click('input[type="submit"]');8  await page.waitForNavigation();9  expect(await page.title()).to.contain('Hello World');10  await browser.close();11})();Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3  const browser = await chromium.launch();4  const page = await browser.newPage();5  const consoleMessage = await page.evaluate(() => {6    const unexpected = window['playwright'].unexpected;7    unexpected.output.preferredWidth = 80;8    unexpected.inspect.styles = {9      tag: (text) => unexpected.output.color.yellow(text),10      name: (text) => unexpected.output.color.green(text),11      string: (text) => unexpected.output.color.cyan(text),12      number: (text) => unexpected.output.color.magenta(text),13      boolean: (text) => unexpected.output.color.cyan(text),14      regexp: (text) => unexpected.output.color.yellow(text),15      null: (text) => unexpected.output.color.cyan(text),16      undefined: (text) => unexpected.output.color.cyan(text),17      date: (text) => unexpected.output.color.yellow(text),18      error: (text) => unexpected.output.color.red(text),19      special: (text) => unexpected.output.color.cyan(text),20      'default': (text) => text21    };22    return unexpected.inspect({ foo: 'bar' });23  });Using AI Code Generation
1import { chromium } from 'playwright';2const browser = await chromium.launch();3const context = await browser.newContext();4const page = await context.newPage();5const unexpected = page._delegate._page._delegate._browserContext._delegate._browser._unexpected;6await unexpected._assertionLibrary.addAssertion('<string> [not] to be a palindrome', async (expect, subject) => {7  expect(subject, 'to equal', subject.split('').reverse().join(''));8});9await page.expect('Playwright', 'to be a palindrome');10await page.expect('Playwright', 'not to be a palindrome');11await browser.close();12import { test, expect } from '@playwright/test';13test('should be a palindrome', async ({ page }) => {14  await expect(page).toHaveText('Playwright');15  await expect(page).not.toHaveText('Playwright');16});Using AI Code Generation
1const { test, expect } = require('@playwright/test');2test('should work', async ({ page }) => {3  await expect(page).toHaveSelector('text=Learn more');4});5const { test, expect } = require('@playwright/test');6test('should work', async ({ page }) => {7  await page.expectSelector('text=Learn more');8});Using AI Code Generation
1const { Page } = require('playwright/lib/server/page');2Page.prototype.unexpected = async function() {3  console.log('unexpected');4}5const { Page } = require('playwright/lib/server/page');6Page.prototype.unexpected = async function() {7  console.log('unexpected');8}9const { Page } = require('playwright/lib/server/page');10Page.prototype.unexpected = async function() {11  console.log('unexpected');12}13const { Page } = require('playwright/lib/server/page');14Page.prototype.unexpected = async function() {15  console.log('unexpected');16}17const { Page } = require('playwright/lib/server/page');18Page.prototype.unexpected = async function() {19  console.log('unexpected');20}21const { Page } = require('playwright/lib/server/page');22Page.prototype.unexpected = async function() {23  console.log('unexpected');24}25const { Page } = require('playwright/lib/server/page');26Page.prototype.unexpected = async function() {27  console.log('unexpected');28}29const { Page } = require('playwright/lib/server/page');30Page.prototype.unexpected = async function() {31  console.log('unexpected');32}33const { Page } = require('playwright/lib/server/page');34Page.prototype.unexpected = async function() {35  console.log('unexpected');36}37const { Page } = require('playwright/lib/server/page');38Page.prototype.unexpected = async function() {39  console.log('unexpected');40}41const { Page } = require('playwright/lib/server/page');42Page.prototype.unexpected = async function() {43  console.log('unexpected');44}45const { Page } = require('playwright/lib/server/page');46Page.prototype.unexpected = async function() {47  console.log('unexpected');48}49const { Page } = require('playwright/lib/server/page');50Page.prototype.unexpected = async function() {51  console.log('unexpected');52}53const { Page } = require('playwright/lib/server/page');LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
