Best JavaScript code snippet using storybook-root
object-property-newline.js
Source:object-property-newline.js
1/**2 * @fileoverview Rule to enforce placing object properties on separate lines.3 * @author Vitor Balocco4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/object-property-newline"),10 RuleTester = require("../../../lib/testers/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("object-property-newline", rule, {16 valid: [17 // default-case18 "var obj = {\nk1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4'\n};",19 "var obj = {\nk1: 'val1'\n, k2: 'val2'\n, k3: 'val3'\n, k4: 'val4'\n};",20 "var obj = { k1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4' };",21 "var obj = { k1: 'val1'\n, k2: 'val2'\n, k3: 'val3'\n, k4: 'val4' };",22 "var obj = { k1: 'val1' };",23 "var obj = {\nk1: 'val1'\n};",24 "var obj = {};",25 { code: "var obj = {\n[bar]: 'baz',\nbaz\n};", parserOptions: { ecmaVersion: 6 } },26 { code: "var obj = {\nk1: 'val1',\nk2: 'val2',\n...{}\n};", parserOptions: { ecmaVersion: 2018 } },27 { code: "var obj = { k1: 'val1',\nk2: 'val2',\n...{} };", parserOptions: { ecmaVersion: 2018 } },28 { code: "var obj = { ...{} };", parserOptions: { ecmaVersion: 2018 } },29 "foo({ k1: 'val1',\nk2: 'val2' });",30 "foo({\nk1: 'val1',\nk2: 'val2'\n});",31 { code: "foo({\na,\nb\n});", parserOptions: { ecmaVersion: 6 } },32 { code: "foo({\na,\nb,\n});", parserOptions: { ecmaVersion: 6 } },33 { code: "foo({\nbar() {},\nbaz\n});", parserOptions: { ecmaVersion: 6 } },34 { code: "foo({\n[bar]: 'baz',\nbaz \n})", parserOptions: { ecmaVersion: 6 } },35 { code: "foo({\nk1: 'val1',\nk2: 'val2',\n...{}\n});", parserOptions: { ecmaVersion: 2018 } },36 { code: "foo({ k1: 'val1',\nk2: 'val2',\n...{} });", parserOptions: { ecmaVersion: 2018 } },37 { code: "foo({ ...{} });", parserOptions: { ecmaVersion: 2018 } },38 // allowAllPropertiesOnSameLine: true39 { code: "var obj = { k1: 'val1', k2: 'val2', k3: 'val3' };", options: [{ allowAllPropertiesOnSameLine: true }] },40 { code: "var obj = {\nk1: 'val1', k2: 'val2', k3: 'val3'\n};", options: [{ allowAllPropertiesOnSameLine: true }] },41 { code: "var obj = { k1: 'val1' };", options: [{ allowAllPropertiesOnSameLine: true }] },42 { code: "var obj = {\nk1: 'val1'\n};", options: [{ allowAllPropertiesOnSameLine: true }] },43 { code: "var obj = {};", options: [{ allowAllPropertiesOnSameLine: true }] },44 { code: "var obj = { 'k1': 'val1', k2: 'val2', ...{} };", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } },45 { code: "var obj = {\n'k1': 'val1', k2: 'val2', ...{}\n};", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } },46 { code: "foo({ k1: 'val1', k2: 'val2' });", options: [{ allowAllPropertiesOnSameLine: true }] },47 { code: "foo({\nk1: 'val1', k2: 'val2'\n});", options: [{ allowAllPropertiesOnSameLine: true }] },48 { code: "foo({ a, b });", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 6 } },49 { code: "foo({ bar() {}, baz });", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 6 } },50 { code: "foo({ [bar]: 'baz', baz })", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 6 } },51 { code: "foo({ 'k1': 'val1', k2: 'val2', ...{} });", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } },52 { code: "foo({\n'k1': 'val1', k2: 'val2', ...{}\n});", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } },53 { code: "var obj = {k1: ['foo', 'bar'], k2: 'val1', k3: 'val2'};", options: [{ allowAllPropertiesOnSameLine: true }] },54 { code: "var obj = {\nk1: ['foo', 'bar'], k2: 'val1', k3: 'val2'\n};", options: [{ allowAllPropertiesOnSameLine: true }] },55 { code: "var obj = {\nk1: 'val1', k2: {e1: 'foo', e2: 'bar'}, k3: 'val2'\n};", options: [{ allowAllPropertiesOnSameLine: true }] },56 // allowMultiplePropertiesPerLine: true (deprecated)57 { code: "var obj = { k1: 'val1', k2: 'val2', k3: 'val3' };", options: [{ allowMultiplePropertiesPerLine: true }] }58 ],59 invalid: [60 // default-case61 {62 code: "var obj = { k1: 'val1', k2: 'val2', k3: 'val3' };",63 output: "var obj = { k1: 'val1',\nk2: 'val2',\nk3: 'val3' };",64 errors: [65 {66 message: "Object properties must go on a new line.",67 type: "ObjectExpression",68 line: 1,69 column: 2570 },71 {72 message: "Object properties must go on a new line.",73 type: "ObjectExpression",74 line: 1,75 column: 3776 }77 ]78 },79 {80 code: "var obj = {\nk1: 'val1', k2: 'val2'\n};",81 output: "var obj = {\nk1: 'val1',\nk2: 'val2'\n};",82 errors: [83 {84 message: "Object properties must go on a new line.",85 type: "ObjectExpression",86 line: 2,87 column: 1388 }89 ]90 },91 {92 code: "var obj = {\nk1: 'val1', k2: 'val2',\nk3: 'val3', k4: 'val4'\n};",93 output: "var obj = {\nk1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4'\n};",94 errors: [95 {96 message: "Object properties must go on a new line.",97 type: "ObjectExpression",98 line: 2,99 column: 13100 },101 {102 message: "Object properties must go on a new line.",103 type: "ObjectExpression",104 line: 3,105 column: 13106 }107 ]108 },109 {110 code: "var obj = {k1: ['foo', 'bar'], k2: 'val1'};",111 output: "var obj = {k1: ['foo', 'bar'],\nk2: 'val1'};",112 errors: [113 {114 message: "Object properties must go on a new line.",115 type: "ObjectExpression",116 line: 1,117 column: 32118 }119 ]120 },121 {122 code: "var obj = {k1: [\n'foo', 'bar'\n], k2: 'val1'};",123 output: "var obj = {k1: [\n'foo', 'bar'\n],\nk2: 'val1'};",124 errors: [125 {126 message: "Object properties must go on a new line.",127 type: "ObjectExpression",128 line: 3,129 column: 4130 }131 ]132 },133 {134 code: "var obj = {\nk1: 'val1', k2: {e1: 'foo', e2: 'bar'}, k3: 'val2'\n};",135 output: "var obj = {\nk1: 'val1',\nk2: {e1: 'foo',\ne2: 'bar'},\nk3: 'val2'\n};",136 errors: [137 {138 message: "Object properties must go on a new line.",139 type: "ObjectExpression",140 line: 2,141 column: 13142 },143 {144 message: "Object properties must go on a new line.",145 type: "ObjectExpression",146 line: 2,147 column: 29148 },149 {150 message: "Object properties must go on a new line.",151 type: "ObjectExpression",152 line: 2,153 column: 41154 }155 ]156 },157 {158 code: "var obj = {\nk1: 'val1',\nk2: {e1: 'foo', e2: 'bar'},\nk3: 'val2'\n};",159 output: "var obj = {\nk1: 'val1',\nk2: {e1: 'foo',\ne2: 'bar'},\nk3: 'val2'\n};",160 errors: [161 {162 message: "Object properties must go on a new line.",163 type: "ObjectExpression",164 line: 3,165 column: 17166 }167 ]168 },169 {170 code: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n], k3: 'val3' };",171 output: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n],\nk3: 'val3' };",172 errors: [173 {174 message: "Object properties must go on a new line.",175 type: "ObjectExpression",176 line: 4,177 column: 4178 }179 ]180 },181 {182 code: "var obj = { k1: 'val1', [\nk2]: 'val2' };",183 output: "var obj = { k1: 'val1',\n[\nk2]: 'val2' };",184 parserOptions: { ecmaVersion: 6 },185 errors: [186 {187 message: "Object properties must go on a new line.",188 type: "ObjectExpression",189 line: 1,190 column: 25191 }192 ]193 },194 {195 code: "var obj = { k1: 'val1', ...{} };",196 output: "var obj = { k1: 'val1',\n...{} };",197 parserOptions: { ecmaVersion: 2018 },198 errors: [199 {200 message: "Object properties must go on a new line.",201 type: "ObjectExpression",202 line: 1,203 column: 25204 }205 ]206 },207 {208 code: "var obj = {\nk1: 'val1', ...{}\n};",209 output: "var obj = {\nk1: 'val1',\n...{}\n};",210 parserOptions: { ecmaVersion: 2018 },211 errors: [212 {213 message: "Object properties must go on a new line.",214 type: "ObjectExpression",215 line: 2,216 column: 13217 }218 ]219 },220 {221 code: "foo({ k1: 'val1', k2: 'val2' });",222 output: "foo({ k1: 'val1',\nk2: 'val2' });",223 errors: [224 {225 message: "Object properties must go on a new line.",226 type: "ObjectExpression",227 line: 1,228 column: 19229 }230 ]231 },232 {233 code: "foo({\nk1: 'val1', k2: 'val2'\n});",234 output: "foo({\nk1: 'val1',\nk2: 'val2'\n});",235 errors: [236 {237 message: "Object properties must go on a new line.",238 type: "ObjectExpression",239 line: 2,240 column: 13241 }242 ]243 },244 {245 code: "foo({ a, b });",246 output: "foo({ a,\nb });",247 parserOptions: { ecmaVersion: 6 },248 errors: [249 {250 message: "Object properties must go on a new line.",251 type: "ObjectExpression",252 line: 1,253 column: 10254 }255 ]256 },257 {258 code: "foo({\na, b\n});",259 output: "foo({\na,\nb\n});",260 parserOptions: { ecmaVersion: 6 },261 errors: [262 {263 message: "Object properties must go on a new line.",264 type: "ObjectExpression",265 line: 2,266 column: 4267 }268 ]269 },270 {271 code: "foo({\nbar() {}, baz\n});",272 output: "foo({\nbar() {},\nbaz\n});",273 parserOptions: { ecmaVersion: 6 },274 errors: [275 {276 message: "Object properties must go on a new line.",277 type: "ObjectExpression",278 line: 2,279 column: 11280 }281 ]282 },283 {284 code: "foo({\n[bar]: 'baz', baz\n})",285 output: "foo({\n[bar]: 'baz',\nbaz\n})",286 parserOptions: { ecmaVersion: 6 },287 errors: [288 {289 message: "Object properties must go on a new line.",290 type: "ObjectExpression",291 line: 2,292 column: 15293 }294 ]295 },296 {297 code: "foo({ k1: 'val1', [\nk2]: 'val2' })",298 output: "foo({ k1: 'val1',\n[\nk2]: 'val2' })",299 parserOptions: { ecmaVersion: 6 },300 errors: [301 {302 message: "Object properties must go on a new line.",303 type: "ObjectExpression",304 line: 1,305 column: 19306 }307 ]308 },309 {310 code: "foo({ k1: 'val1', ...{} })",311 output: "foo({ k1: 'val1',\n...{} })",312 parserOptions: { ecmaVersion: 2018 },313 errors: [314 {315 message: "Object properties must go on a new line.",316 type: "ObjectExpression",317 line: 1,318 column: 19319 }320 ]321 },322 {323 code: "foo({\nk1: 'val1', ...{}\n})",324 output: "foo({\nk1: 'val1',\n...{}\n})",325 parserOptions: { ecmaVersion: 2018 },326 errors: [327 {328 message: "Object properties must go on a new line.",329 type: "ObjectExpression",330 line: 2,331 column: 13332 }333 ]334 },335 {336 code: "var obj = {\na: {\nb: 1,\nc: 2\n}, d: 2\n};",337 output: "var obj = {\na: {\nb: 1,\nc: 2\n},\nd: 2\n};",338 errors: [339 {340 message: "Object properties must go on a new line.",341 type: "ObjectExpression",342 line: 5,343 column: 4344 }345 ]346 },347 {348 code: "({ foo: 1 /* comment */, bar: 2 })",349 output: "({ foo: 1 /* comment */,\nbar: 2 })",350 errors: [351 {352 message: "Object properties must go on a new line.",353 type: "ObjectExpression",354 line: 1,355 column: 26356 }357 ]358 },359 {360 code: "({ foo: 1, /* comment */ bar: 2 })",361 output: null, // not fixed due to comment362 errors: [363 {364 message: "Object properties must go on a new line.",365 type: "ObjectExpression",366 line: 1,367 column: 26368 }369 ]370 },371 // allowAllPropertiesOnSameLine: true372 {373 code: "var obj = {\nk1: 'val1',\nk2: 'val2', k3: 'val3'\n};",374 output: "var obj = {\nk1: 'val1',\nk2: 'val2',\nk3: 'val3'\n};",375 options: [{ allowAllPropertiesOnSameLine: true }],376 errors: [377 {378 message: "Object properties must go on a new line if they aren't all on the same line.",379 type: "ObjectExpression",380 line: 3,381 column: 13382 }383 ]384 },385 {386 code: "var obj = {\nk1:\n'val1', k2: 'val2', k3:\n'val3'\n};",387 output: "var obj = {\nk1:\n'val1',\nk2: 'val2',\nk3:\n'val3'\n};",388 options: [{ allowAllPropertiesOnSameLine: true }],389 errors: [390 {391 message: "Object properties must go on a new line if they aren't all on the same line.",392 type: "ObjectExpression",393 line: 3,394 column: 9395 },396 {397 message: "Object properties must go on a new line if they aren't all on the same line.",398 type: "ObjectExpression",399 line: 3,400 column: 21401 }402 ]403 },404 {405 code: "var obj = {k1: [\n'foo',\n'bar'\n], k2: 'val1'};",406 output: "var obj = {k1: [\n'foo',\n'bar'\n],\nk2: 'val1'};",407 options: [{ allowAllPropertiesOnSameLine: true }],408 errors: [409 {410 message: "Object properties must go on a new line if they aren't all on the same line.",411 type: "ObjectExpression",412 line: 4,413 column: 4414 }415 ]416 },417 {418 code: "var obj = {k1: [\n'foo', 'bar'\n], k2: 'val1'};",419 output: "var obj = {k1: [\n'foo', 'bar'\n],\nk2: 'val1'};",420 options: [{ allowAllPropertiesOnSameLine: true }],421 errors: [422 {423 message: "Object properties must go on a new line if they aren't all on the same line.",424 type: "ObjectExpression",425 line: 3,426 column: 4427 }428 ]429 },430 {431 code: "var obj = {\nk1: 'val1', k2: {\ne1: 'foo', e2: 'bar'\n}, k3: 'val2'\n};",432 output: "var obj = {\nk1: 'val1',\nk2: {\ne1: 'foo', e2: 'bar'\n},\nk3: 'val2'\n};",433 options: [{ allowAllPropertiesOnSameLine: true }],434 errors: [435 {436 message: "Object properties must go on a new line if they aren't all on the same line.",437 type: "ObjectExpression",438 line: 2,439 column: 13440 },441 {442 message: "Object properties must go on a new line if they aren't all on the same line.",443 type: "ObjectExpression",444 line: 4,445 column: 4446 }447 ]448 },449 {450 code: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n], k3: 'val3' };",451 output: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n],\nk3: 'val3' };",452 options: [{ allowAllPropertiesOnSameLine: true }],453 errors: [454 {455 message: "Object properties must go on a new line if they aren't all on the same line.",456 type: "ObjectExpression",457 line: 4,458 column: 4459 }460 ]461 },462 {463 code: "var obj = { [\nk1]: 'val1', k2: 'val2' };",464 output: "var obj = { [\nk1]: 'val1',\nk2: 'val2' };",465 options: [{ allowAllPropertiesOnSameLine: true }],466 parserOptions: { ecmaVersion: 6 },467 errors: [468 {469 message: "Object properties must go on a new line if they aren't all on the same line.",470 type: "ObjectExpression",471 line: 2,472 column: 14473 }474 ]475 },476 {477 code: "var obj = {\nk1: 'val1',\nk2: 'val2', ...{}\n};",478 output: "var obj = {\nk1: 'val1',\nk2: 'val2',\n...{}\n};",479 options: [{ allowAllPropertiesOnSameLine: true }],480 parserOptions: { ecmaVersion: 2018 },481 errors: [482 {483 message: "Object properties must go on a new line if they aren't all on the same line.",484 type: "ObjectExpression",485 line: 3,486 column: 13487 }488 ]489 },490 {491 code: "var obj = {\n...{},\nk1: 'val1', k2: 'val2'\n};",492 output: "var obj = {\n...{},\nk1: 'val1',\nk2: 'val2'\n};",493 options: [{ allowAllPropertiesOnSameLine: true }],494 parserOptions: { ecmaVersion: 2018 },495 errors: [496 {497 message: "Object properties must go on a new line if they aren't all on the same line.",498 type: "ObjectExpression",499 line: 3,500 column: 13501 }502 ]503 },504 {505 code: "foo({ [\nk1]: 'val1', k2: 'val2' })",506 output: "foo({ [\nk1]: 'val1',\nk2: 'val2' })",507 options: [{ allowAllPropertiesOnSameLine: true }],508 parserOptions: { ecmaVersion: 6 },509 errors: [510 {511 message: "Object properties must go on a new line if they aren't all on the same line.",512 type: "ObjectExpression",513 line: 2,514 column: 14515 }516 ]517 },518 {519 code: "foo({\nk1: 'val1',\nk2: 'val2', ...{}\n})",520 output: "foo({\nk1: 'val1',\nk2: 'val2',\n...{}\n})",521 options: [{ allowAllPropertiesOnSameLine: true }],522 parserOptions: { ecmaVersion: 2018 },523 errors: [524 {525 message: "Object properties must go on a new line if they aren't all on the same line.",526 type: "ObjectExpression",527 line: 3,528 column: 13529 }530 ]531 },532 {533 code: "foo({\n...{},\nk1: 'val1', k2: 'val2'\n})",534 output: "foo({\n...{},\nk1: 'val1',\nk2: 'val2'\n})",535 options: [{ allowAllPropertiesOnSameLine: true }],536 parserOptions: { ecmaVersion: 2018 },537 errors: [538 {539 message: "Object properties must go on a new line if they aren't all on the same line.",540 type: "ObjectExpression",541 line: 3,542 column: 13543 }544 ]545 },546 // allowMultiplePropertiesPerLine: true (deprecated)547 {548 code: "var obj = {\nk1: 'val1',\nk2: 'val2', k3: 'val3'\n};",549 output: "var obj = {\nk1: 'val1',\nk2: 'val2',\nk3: 'val3'\n};",550 options: [{ allowMultiplePropertiesPerLine: true }],551 errors: [552 {553 message: "Object properties must go on a new line if they aren't all on the same line.",554 type: "ObjectExpression",555 line: 3,556 column: 13557 }558 ]559 }560 ]...
internal-no-invalid-meta.js
Source:internal-no-invalid-meta.js
1/**2 * @fileoverview Internal rule to prevent missing or invalid meta property in core rules.3 * @author Vitor Balocco4 */5"use strict";6//------------------------------------------------------------------------------7// Helpers8//------------------------------------------------------------------------------9/**10 * Gets the property of the Object node passed in that has the name specified.11 *12 * @param {string} property Name of the property to return.13 * @param {ASTNode} node The ObjectExpression node.14 * @returns {ASTNode} The Property node or null if not found.15 */16function getPropertyFromObject(property, node) {17 const properties = node.properties;18 for (let i = 0; i < properties.length; i++) {19 if (properties[i].key.name === property) {20 return properties[i];21 }22 }23 return null;24}25/**26 * Extracts the `meta` property from the ObjectExpression that all rules export.27 *28 * @param {ASTNode} exportsNode ObjectExpression node that the rule exports.29 * @returns {ASTNode} The `meta` Property node or null if not found.30 */31function getMetaPropertyFromExportsNode(exportsNode) {32 return getPropertyFromObject("meta", exportsNode);33}34/**35 * Whether this `meta` ObjectExpression has a `docs` property defined or not.36 *37 * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.38 * @returns {boolean} `true` if a `docs` property exists.39 */40function hasMetaDocs(metaPropertyNode) {41 return Boolean(getPropertyFromObject("docs", metaPropertyNode.value));42}43/**44 * Whether this `meta` ObjectExpression has a `docs.description` property defined or not.45 *46 * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.47 * @returns {boolean} `true` if a `docs.description` property exists.48 */49function hasMetaDocsDescription(metaPropertyNode) {50 const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value);51 return metaDocs && getPropertyFromObject("description", metaDocs.value);52}53/**54 * Whether this `meta` ObjectExpression has a `docs.category` property defined or not.55 *56 * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.57 * @returns {boolean} `true` if a `docs.category` property exists.58 */59function hasMetaDocsCategory(metaPropertyNode) {60 const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value);61 return metaDocs && getPropertyFromObject("category", metaDocs.value);62}63/**64 * Whether this `meta` ObjectExpression has a `docs.recommended` property defined or not.65 *66 * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.67 * @returns {boolean} `true` if a `docs.recommended` property exists.68 */69function hasMetaDocsRecommended(metaPropertyNode) {70 const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value);71 return metaDocs && getPropertyFromObject("recommended", metaDocs.value);72}73/**74 * Whether this `meta` ObjectExpression has a `schema` property defined or not.75 *76 * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.77 * @returns {boolean} `true` if a `schema` property exists.78 */79function hasMetaSchema(metaPropertyNode) {80 return getPropertyFromObject("schema", metaPropertyNode.value);81}82/**83 * Whether this `meta` ObjectExpression has a `fixable` property defined or not.84 *85 * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.86 * @returns {boolean} `true` if a `fixable` property exists.87 */88function hasMetaFixable(metaPropertyNode) {89 return getPropertyFromObject("fixable", metaPropertyNode.value);90}91/**92 * Checks the validity of the meta definition of this rule and reports any errors found.93 *94 * @param {RuleContext} context The ESLint rule context.95 * @param {ASTNode} exportsNode ObjectExpression node that the rule exports.96 * @param {boolean} ruleIsFixable whether the rule is fixable or not.97 * @returns {void}98 */99function checkMetaValidity(context, exportsNode, ruleIsFixable) {100 const metaProperty = getMetaPropertyFromExportsNode(exportsNode);101 if (!metaProperty) {102 context.report(exportsNode, "Rule is missing a meta property.");103 return;104 }105 if (!hasMetaDocs(metaProperty)) {106 context.report(metaProperty, "Rule is missing a meta.docs property.");107 return;108 }109 if (!hasMetaDocsDescription(metaProperty)) {110 context.report(metaProperty, "Rule is missing a meta.docs.description property.");111 return;112 }113 if (!hasMetaDocsCategory(metaProperty)) {114 context.report(metaProperty, "Rule is missing a meta.docs.category property.");115 return;116 }117 if (!hasMetaDocsRecommended(metaProperty)) {118 context.report(metaProperty, "Rule is missing a meta.docs.recommended property.");119 return;120 }121 if (!hasMetaSchema(metaProperty)) {122 context.report(metaProperty, "Rule is missing a meta.schema property.");123 return;124 }125 if (ruleIsFixable && !hasMetaFixable(metaProperty)) {126 context.report(metaProperty, "Rule is fixable, but is missing a meta.fixable property.");127 return;128 }129}130/**131 * Whether this node is the correct format for a rule definition or not.132 *133 * @param {ASTNode} node node that the rule exports.134 * @returns {boolean} `true` if the exported node is the correct format for a rule definition135 */136function isCorrectExportsFormat(node) {137 return node.type === "ObjectExpression";138}139//------------------------------------------------------------------------------140// Rule Definition141//------------------------------------------------------------------------------142module.exports = {143 meta: {144 docs: {145 description: "enforce correct use of `meta` property in core rules",146 category: "Internal",147 recommended: false148 },149 schema: []150 },151 create(context) {152 let exportsNode;153 let ruleIsFixable = false;154 return {155 AssignmentExpression(node) {156 if (node.left &&157 node.right &&158 node.left.type === "MemberExpression" &&159 node.left.object.name === "module" &&160 node.left.property.name === "exports") {161 exportsNode = node.right;162 }163 },164 CallExpression(node) {165 // If the rule has a call for `context.report` and a property `fix`166 // is being passed in, then we consider that the rule is fixable.167 //168 // Note that we only look for context.report() calls in the new169 // style (with single MessageDescriptor argument), because only170 // calls in the new style can specify a fix.171 if (node.callee.type === "MemberExpression" &&172 node.callee.object.type === "Identifier" &&173 node.callee.object.name === "context" &&174 node.callee.property.type === "Identifier" &&175 node.callee.property.name === "report" &&176 node.arguments.length === 1 &&177 node.arguments[0].type === "ObjectExpression") {178 if (getPropertyFromObject("fix", node.arguments[0])) {179 ruleIsFixable = true;180 }181 }182 },183 "Program:exit"() {184 if (!isCorrectExportsFormat(exportsNode)) {185 context.report(exportsNode, "Rule does not export an Object. Make sure the rule follows the new rule format.");186 return;187 }188 checkMetaValidity(context, exportsNode, ruleIsFixable);189 }190 };191 }...
no-dupe-keys.js
Source:no-dupe-keys.js
1/**2 * @fileoverview Tests for no-dupe-keys rule.3 * @author Ian Christian Myers4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/no-dupe-keys"),10 { RuleTester } = require("../../../lib/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("no-dupe-keys", rule, {16 valid: [17 "var foo = { __proto__: 1, two: 2};",18 "var x = { foo: 1, bar: 2 };",19 "var x = { '': 1, bar: 2 };",20 "var x = { '': 1, ' ': 2 };",21 { code: "var x = { '': 1, [null]: 2 };", parserOptions: { ecmaVersion: 6 } },22 { code: "var x = { '': 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } },23 { code: "var x = { [a]: 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } },24 "+{ get a() { }, set a(b) { } };",25 { code: "var x = { a: b, [a]: b };", parserOptions: { ecmaVersion: 6 } },26 { code: "var x = { a: b, ...c }", parserOptions: { ecmaVersion: 2018 } },27 { code: "var x = { get a() {}, set a (value) {} };", parserOptions: { ecmaVersion: 6 } },28 { code: "var x = { a: 1, b: { a: 2 } };", parserOptions: { ecmaVersion: 6 } },29 { code: "var x = ({ null: 1, [/(?<zero>0)/]: 2 })", parserOptions: { ecmaVersion: 2018 } },30 { code: "var {a, a} = obj", parserOptions: { ecmaVersion: 6 } },31 "var x = { 012: 1, 12: 2 };",32 { code: "var x = { 1_0: 1, 1: 2 };", parserOptions: { ecmaVersion: 2021 } }33 ],34 invalid: [35 { code: "var x = { a: b, ['a']: b };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] },36 { code: "var x = { y: 1, y: 2 };", errors: [{ messageId: "unexpected", data: { name: "y" }, type: "ObjectExpression" }] },37 { code: "var x = { '': 1, '': 2 };", errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] },38 { code: "var x = { '': 1, [``]: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] },39 { code: "var foo = { 0x1: 1, 1: 2};", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] },40 { code: "var x = { 012: 1, 10: 2 };", errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }] },41 { code: "var x = { 0b1: 1, 1: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] },42 { code: "var x = { 0o1: 1, 1: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] },43 { code: "var x = { 1n: 1, 1: 2 };", parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] },44 { code: "var x = { 1_0: 1, 10: 2 };", parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }] },45 { code: "var x = { \"z\": 1, z: 2 };", errors: [{ messageId: "unexpected", data: { name: "z" }, type: "ObjectExpression" }] },46 { code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ messageId: "unexpected", data: { name: "bar" }, line: 3, column: 3 }] },47 { code: "var x = { a: 1, get a() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] },48 { code: "var x = { a: 1, set a(value) {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] },49 { code: "var x = { a: 1, b: { a: 2 }, get b() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "b" }, type: "ObjectExpression" }] },50 { code: "var x = ({ '/(?<zero>0)/': 1, [/(?<zero>0)/]: 2 })", parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "unexpected", data: { name: "/(?<zero>0)/" }, type: "ObjectExpression" }] }51 ]...
Using AI Code Generation
1import { addDecorator } from '@storybook/react';2import { withRoot } from 'storybook-root-decorator';3addDecorator(withRoot);4import { addDecorator } from '@storybook/react';5import { withRoot } from 'storybook-root-decorator';6addDecorator(story => <withRoot>{story()}</withRoot>);7import { addDecorator } from '@storybook/react';8import { withRoot } from 'storybook-root-decorator';9addDecorator(withRoot);10import { addDecorator } from '@storybook/react';11import { withRoot } from 'storybook-root-decorator';12addDecorator(story => <withRoot>{story()}</withRoot>);13import { addDecorator } from '@storybook/react';14import { withRoot } from 'storybook-root-decorator';15addDecorator(withRoot);16import { addDecorator } from '@storybook/react';17import { withRoot } from 'storybook-root-decorator';18addDecorator(story => <withRoot>{story()}</withRoot>);19import { addDecorator } from '@storybook/react';20import { withRoot } from 'storybook-root-decorator';21addDecorator(withRoot);22import { addDecorator } from '@storybook/react';23import { withRoot } from 'storybook-root-decorator';24addDecorator(story => <withRoot>{story()}</withRoot>);25import { addDecorator } from '@storybook/react';26import { withRoot } from 'storybook-root-decorator';27addDecorator(withRoot);28import { addDecorator } from '@storybook/react';29import { withRoot } from 'storybook-root-decorator';30addDecorator(story => <withRoot>{story()}</withRoot>);
Using AI Code Generation
1import { storiesOf } from 'storybook-root';2storiesOf('test')3 .add('test', () => <div>test</div>);4import { storiesOf } from 'storybook-root';5storiesOf('test2')6 .add('test2', () => <div>test2</div>);7import { storiesOf } from 'storybook-root';8storiesOf('test3')9 .add('test3', () => <div>test3</div>);10import { storiesOf } from 'storybook-root';11storiesOf('test4')12 .add('test4', () => <div>test4</div>);13import { storiesOf } from 'storybook-root';14storiesOf('test5')15 .add('test5', () => <div>test5</div>);16import { storiesOf } from 'storybook-root';17storiesOf('test6')18 .add('test6', () => <div>test6</div>);19import { storiesOf } from 'storybook-root';20storiesOf('test7')21 .add('test7', () => <div>test7</div>);22import { storiesOf } from 'storybook-root';23storiesOf('test8')24 .add('test8', () => <div>test8</div>);25import { storiesOf } from 'storybook-root';26storiesOf('test9')27 .add('test9', () => <div>test9</div>);28import { storiesOf } from 'storybook-root';29storiesOf('test10')30 .add('test10', () =>
Using AI Code Generation
1import { storiesOf } from 'storybook-root';2storiesOf('Button', module)3 .add('with text', () => ({4 props: {5 }6 }))7 .add('with some emoji', () => ({8 props: {9 }10 }));
Using AI Code Generation
1const storybookRoot = require('storybook-root');2const path = require('path');3const storybookRootPath = storybookRoot();4console.log(storybookRootPath);5const storybookRoot = require('storybook-root');6const path = require('path');7const storybookRootPath = storybookRoot(path.join(__dirname, 'test.js'));8console.log(storybookRootPath);9const storybookRoot = require('storybook-root');10const storybookRootPath = storybookRoot();11console.log(storybookRootPath);12const storybookRoot = require('storybook-root');13const path = require('path');14const storybookRootPath = storybookRoot(path.join(__dirname, 'test.js'));15console.log(storybookRootPath);16const storybookRoot = require('storybook-root');17const storybookRootPath = storybookRoot();18console.log(storybookRootPath);19const storybookRoot = require('storybook-root');20const path = require('path');21const storybookRootPath = storybookRoot(path.join(__dirname, 'test.js'));22console.log(storybookRootPath);23const storybookRoot = require('storybook-root');24const storybookRootPath = storybookRoot();25console.log(storybookRootPath);26const storybookRoot = require('storybook-root');27const path = require('path');28const storybookRootPath = storybookRoot(path.join(__dirname, 'test.js'));29console.log(storybookRootPath);30const storybookRoot = require('storybook-root');31const storybookRootPath = storybookRoot();32console.log(storybookRootPath);33const storybookRoot = require('storybook-root');34const path = require('path');35const storybookRootPath = storybookRoot(path.join(__dirname, 'test.js'));36console.log(storybookRootPath);37const storybookRoot = require('storybook-root');38const storybookRootPath = storybookRoot();39console.log(storybookRootPath);40const storybookRoot = require('storybook-root');41const path = require('path');42const storybookRootPath = storybookRoot(path.join(__dirname, 'test.js'));43console.log(storybookRootPath);44const storybookRoot = require('storybook-root');45const storybookRootPath = storybookRoot();46console.log(storybookRootPath);47const storybookRoot = require('storybook-root');48const path = require('path');
Using AI Code Generation
1import { addDecorator } from 'storybook-root-decorator';2import { withInfo } from '@storybook/addon-info';3addDecorator(withInfo);4import { configure } from '@storybook/react';5import 'storybook-root-decorator/register';6configure(require.context('../src', true, /\.stories\.js$/), module);7import { addDecorator } from 'storybook-root-decorator';8import { withInfo } from '@storybook/addon-info';9addDecorator(withInfo);10import { addons } from '@storybook/addons';11addons.setConfig({12});13import 'storybook-root-decorator/register';14module.exports = {15};16module.exports = async ({ config, mode }) => {17 config.resolve.alias = {18 'storybook-root-decorator': require.resolve('storybook-root-decorator'),19 };20 return config;21};22{23 "compilerOptions": {24 "paths": {25 }26 }27}28module.exports = function(api) {29 api.cache(true);30 return {31 {32 alias: {33 },34 },35 };36};37import { addDecorator } from 'storybook-root-decorator';38import { withInfo
Using AI Code Generation
1var root = require("storybook-root");2var story = root.ObjectExpression();3story.addProperty("name", "test");4story.save("testStory");5var root = require("storybook-root");6var story = root.ObjectExpression();7story.addProperty("name", "test2");8story.save("testStory2");9var root = require("storybook-root");10var story = root.ObjectExpression();11story.addProperty("name", "test3");12story.save("testStory3");13var root = require("storybook-root");14var story = root.ObjectExpression();15story.addProperty("name", "test4");16story.save("testStory4");17var root = require("storybook-root");18var story = root.ObjectExpression();19story.addProperty("name", "test5");20story.save("testStory5");21var root = require("storybook-root");22var story = root.ObjectExpression();23story.addProperty("name", "test6");24story.save("testStory6");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!