@agilebot/eslint-plugin 0.2.6 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +246 -246
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license @agilebot/eslint-plugin v0.
|
2
|
+
* @license @agilebot/eslint-plugin v0.3.1
|
3
3
|
*
|
4
4
|
* Copyright (c) Agilebot, Inc. and its affiliates.
|
5
5
|
*
|
@@ -521,6 +521,251 @@ var noDefault = {
|
|
521
521
|
}
|
522
522
|
};
|
523
523
|
|
524
|
+
function getBasicIdentifier(node) {
|
525
|
+
if (node.type === 'Identifier') {
|
526
|
+
return node.name;
|
527
|
+
}
|
528
|
+
if (node.type === 'Literal') {
|
529
|
+
return node.value;
|
530
|
+
}
|
531
|
+
if (node.type === 'TemplateLiteral') {
|
532
|
+
if (node.expressions.length > 0) {
|
533
|
+
return null;
|
534
|
+
}
|
535
|
+
return node.quasis[0].value.raw;
|
536
|
+
}
|
537
|
+
return null;
|
538
|
+
}
|
539
|
+
function getBaseIdentifier(node) {
|
540
|
+
switch (node.type) {
|
541
|
+
case 'Identifier': {
|
542
|
+
return node;
|
543
|
+
}
|
544
|
+
case 'CallExpression': {
|
545
|
+
return getBaseIdentifier(node.callee);
|
546
|
+
}
|
547
|
+
case 'MemberExpression': {
|
548
|
+
return getBaseIdentifier(node.object);
|
549
|
+
}
|
550
|
+
}
|
551
|
+
return null;
|
552
|
+
}
|
553
|
+
function getStyesObj(node) {
|
554
|
+
const isMakeStyles = node.callee.name === 'makeStyles';
|
555
|
+
const isModernApi =
|
556
|
+
node.callee.type === 'MemberExpression' &&
|
557
|
+
node.callee.property.name === 'create' &&
|
558
|
+
getBaseIdentifier(node.callee.object) &&
|
559
|
+
getBaseIdentifier(node.callee.object).name === 'tss';
|
560
|
+
if (!isMakeStyles && !isModernApi) {
|
561
|
+
return;
|
562
|
+
}
|
563
|
+
const styles = (() => {
|
564
|
+
if (isMakeStyles) {
|
565
|
+
return node.parent.arguments[0];
|
566
|
+
}
|
567
|
+
if (isModernApi) {
|
568
|
+
return node.callee.parent.arguments[0];
|
569
|
+
}
|
570
|
+
})();
|
571
|
+
if (!styles) {
|
572
|
+
return;
|
573
|
+
}
|
574
|
+
switch (styles.type) {
|
575
|
+
case 'ObjectExpression':
|
576
|
+
return styles;
|
577
|
+
case 'ArrowFunctionExpression':
|
578
|
+
{
|
579
|
+
const { body } = styles;
|
580
|
+
switch (body.type) {
|
581
|
+
case 'ObjectExpression':
|
582
|
+
return body;
|
583
|
+
case 'BlockStatement': {
|
584
|
+
let stylesObj;
|
585
|
+
body.body.forEach(bodyNode => {
|
586
|
+
if (
|
587
|
+
bodyNode.type === 'ReturnStatement' &&
|
588
|
+
bodyNode.argument.type === 'ObjectExpression'
|
589
|
+
) {
|
590
|
+
stylesObj = bodyNode.argument;
|
591
|
+
}
|
592
|
+
});
|
593
|
+
return stylesObj;
|
594
|
+
}
|
595
|
+
}
|
596
|
+
}
|
597
|
+
break;
|
598
|
+
}
|
599
|
+
}
|
600
|
+
|
601
|
+
var classNaming = {
|
602
|
+
meta: {
|
603
|
+
type: 'problem'
|
604
|
+
},
|
605
|
+
create: function rule(context) {
|
606
|
+
return {
|
607
|
+
CallExpression(node) {
|
608
|
+
const stylesObj = getStyesObj(node);
|
609
|
+
if (stylesObj === undefined) {
|
610
|
+
return;
|
611
|
+
}
|
612
|
+
stylesObj.properties.forEach(property => {
|
613
|
+
if (property.computed) {
|
614
|
+
return;
|
615
|
+
}
|
616
|
+
if (
|
617
|
+
property.type === 'ExperimentalSpreadProperty' ||
|
618
|
+
property.type === 'SpreadElement'
|
619
|
+
) {
|
620
|
+
return;
|
621
|
+
}
|
622
|
+
const className = property.key.value || property.key.name;
|
623
|
+
if (!eslintUtils.isCamelCase(className)) {
|
624
|
+
context.report({
|
625
|
+
node: property,
|
626
|
+
message: `Class \`${className}\` must be camelCase in TSS.`
|
627
|
+
});
|
628
|
+
}
|
629
|
+
});
|
630
|
+
}
|
631
|
+
};
|
632
|
+
}
|
633
|
+
};
|
634
|
+
|
635
|
+
var noColorValue = {
|
636
|
+
meta: {
|
637
|
+
type: 'problem',
|
638
|
+
docs: {
|
639
|
+
description:
|
640
|
+
'Enforce the use of color variables instead of color codes within TSS'
|
641
|
+
}
|
642
|
+
},
|
643
|
+
create: function (context) {
|
644
|
+
const parserOptions = context.parserOptions;
|
645
|
+
if (!parserOptions || !parserOptions.project) {
|
646
|
+
return {};
|
647
|
+
}
|
648
|
+
return {
|
649
|
+
CallExpression(node) {
|
650
|
+
const stylesObj = getStyesObj(node);
|
651
|
+
if (!stylesObj) {
|
652
|
+
return;
|
653
|
+
}
|
654
|
+
function checkColorLiteral(value) {
|
655
|
+
if (value.type === 'Literal' && typeof value.value === 'string') {
|
656
|
+
const colorCodePattern =
|
657
|
+
/#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgb\?\(\s*(\d{1,3}\s*,\s*){2}\d{1,3}(?:\s*,\s*\d*(?:\.\d+)?)?\s*\)/g;
|
658
|
+
const isColorCode = colorCodePattern.test(value.value);
|
659
|
+
if (isColorCode) {
|
660
|
+
context.report({
|
661
|
+
node: value,
|
662
|
+
message: 'Use color variables instead of color codes in TSS.'
|
663
|
+
});
|
664
|
+
}
|
665
|
+
}
|
666
|
+
}
|
667
|
+
function loopStylesObj(obj) {
|
668
|
+
if (obj && obj.type === 'ObjectExpression') {
|
669
|
+
obj.properties.forEach(property => {
|
670
|
+
if (property.type === 'Property' && property.value) {
|
671
|
+
if (property.value.type === 'ObjectExpression') {
|
672
|
+
loopStylesObj(property.value);
|
673
|
+
} else {
|
674
|
+
checkColorLiteral(property.value);
|
675
|
+
}
|
676
|
+
}
|
677
|
+
});
|
678
|
+
}
|
679
|
+
}
|
680
|
+
loopStylesObj(stylesObj);
|
681
|
+
}
|
682
|
+
};
|
683
|
+
}
|
684
|
+
};
|
685
|
+
|
686
|
+
var unusedClasses = {
|
687
|
+
meta: {
|
688
|
+
type: 'problem'
|
689
|
+
},
|
690
|
+
create: function rule(context) {
|
691
|
+
const usedClasses = {};
|
692
|
+
const definedClasses = {};
|
693
|
+
return {
|
694
|
+
CallExpression(node) {
|
695
|
+
const stylesObj = getStyesObj(node);
|
696
|
+
if (stylesObj === undefined) {
|
697
|
+
return;
|
698
|
+
}
|
699
|
+
stylesObj.properties.forEach(property => {
|
700
|
+
if (property.computed) {
|
701
|
+
return;
|
702
|
+
}
|
703
|
+
if (
|
704
|
+
property.type === 'ExperimentalSpreadProperty' ||
|
705
|
+
property.type === 'SpreadElement'
|
706
|
+
) {
|
707
|
+
return;
|
708
|
+
}
|
709
|
+
definedClasses[property.key.value || property.key.name] = property;
|
710
|
+
});
|
711
|
+
},
|
712
|
+
MemberExpression(node) {
|
713
|
+
if (
|
714
|
+
node.object.type === 'Identifier' &&
|
715
|
+
node.object.name === 'classes'
|
716
|
+
) {
|
717
|
+
const whichClass = getBasicIdentifier(node.property);
|
718
|
+
if (whichClass) {
|
719
|
+
usedClasses[whichClass] = true;
|
720
|
+
}
|
721
|
+
return;
|
722
|
+
}
|
723
|
+
const classIdentifier = getBasicIdentifier(node.property);
|
724
|
+
if (!classIdentifier) {
|
725
|
+
return;
|
726
|
+
}
|
727
|
+
if (classIdentifier !== 'classes') {
|
728
|
+
return;
|
729
|
+
}
|
730
|
+
const { parent } = node;
|
731
|
+
if (parent.type !== 'MemberExpression') {
|
732
|
+
return;
|
733
|
+
}
|
734
|
+
if (
|
735
|
+
node.object.object &&
|
736
|
+
node.object.object.type !== 'ThisExpression'
|
737
|
+
) {
|
738
|
+
return;
|
739
|
+
}
|
740
|
+
const propsIdentifier = getBasicIdentifier(parent.object);
|
741
|
+
if (propsIdentifier && propsIdentifier !== 'props') {
|
742
|
+
return;
|
743
|
+
}
|
744
|
+
if (!propsIdentifier && parent.object.type !== 'MemberExpression') {
|
745
|
+
return;
|
746
|
+
}
|
747
|
+
if (parent.parent.type === 'MemberExpression') {
|
748
|
+
return;
|
749
|
+
}
|
750
|
+
const parentClassIdentifier = getBasicIdentifier(parent.property);
|
751
|
+
if (parentClassIdentifier) {
|
752
|
+
usedClasses[parentClassIdentifier] = true;
|
753
|
+
}
|
754
|
+
},
|
755
|
+
'Program:exit': () => {
|
756
|
+
Object.keys(definedClasses).forEach(definedClassKey => {
|
757
|
+
if (!usedClasses[definedClassKey]) {
|
758
|
+
context.report({
|
759
|
+
node: definedClasses[definedClassKey],
|
760
|
+
message: `Class \`${definedClassKey}\` is unused`
|
761
|
+
});
|
762
|
+
}
|
763
|
+
});
|
764
|
+
}
|
765
|
+
};
|
766
|
+
}
|
767
|
+
};
|
768
|
+
|
524
769
|
var betterExhaustiveDeps = {
|
525
770
|
meta: {
|
526
771
|
type: 'suggestion',
|
@@ -2287,251 +2532,6 @@ var noUnnecessaryTemplateLiterals = {
|
|
2287
2532
|
}
|
2288
2533
|
};
|
2289
2534
|
|
2290
|
-
function getBasicIdentifier(node) {
|
2291
|
-
if (node.type === 'Identifier') {
|
2292
|
-
return node.name;
|
2293
|
-
}
|
2294
|
-
if (node.type === 'Literal') {
|
2295
|
-
return node.value;
|
2296
|
-
}
|
2297
|
-
if (node.type === 'TemplateLiteral') {
|
2298
|
-
if (node.expressions.length > 0) {
|
2299
|
-
return null;
|
2300
|
-
}
|
2301
|
-
return node.quasis[0].value.raw;
|
2302
|
-
}
|
2303
|
-
return null;
|
2304
|
-
}
|
2305
|
-
function getBaseIdentifier(node) {
|
2306
|
-
switch (node.type) {
|
2307
|
-
case 'Identifier': {
|
2308
|
-
return node;
|
2309
|
-
}
|
2310
|
-
case 'CallExpression': {
|
2311
|
-
return getBaseIdentifier(node.callee);
|
2312
|
-
}
|
2313
|
-
case 'MemberExpression': {
|
2314
|
-
return getBaseIdentifier(node.object);
|
2315
|
-
}
|
2316
|
-
}
|
2317
|
-
return null;
|
2318
|
-
}
|
2319
|
-
function getStyesObj(node) {
|
2320
|
-
const isMakeStyles = node.callee.name === 'makeStyles';
|
2321
|
-
const isModernApi =
|
2322
|
-
node.callee.type === 'MemberExpression' &&
|
2323
|
-
node.callee.property.name === 'create' &&
|
2324
|
-
getBaseIdentifier(node.callee.object) &&
|
2325
|
-
getBaseIdentifier(node.callee.object).name === 'tss';
|
2326
|
-
if (!isMakeStyles && !isModernApi) {
|
2327
|
-
return;
|
2328
|
-
}
|
2329
|
-
const styles = (() => {
|
2330
|
-
if (isMakeStyles) {
|
2331
|
-
return node.parent.arguments[0];
|
2332
|
-
}
|
2333
|
-
if (isModernApi) {
|
2334
|
-
return node.callee.parent.arguments[0];
|
2335
|
-
}
|
2336
|
-
})();
|
2337
|
-
if (!styles) {
|
2338
|
-
return;
|
2339
|
-
}
|
2340
|
-
switch (styles.type) {
|
2341
|
-
case 'ObjectExpression':
|
2342
|
-
return styles;
|
2343
|
-
case 'ArrowFunctionExpression':
|
2344
|
-
{
|
2345
|
-
const { body } = styles;
|
2346
|
-
switch (body.type) {
|
2347
|
-
case 'ObjectExpression':
|
2348
|
-
return body;
|
2349
|
-
case 'BlockStatement': {
|
2350
|
-
let stylesObj;
|
2351
|
-
body.body.forEach(bodyNode => {
|
2352
|
-
if (
|
2353
|
-
bodyNode.type === 'ReturnStatement' &&
|
2354
|
-
bodyNode.argument.type === 'ObjectExpression'
|
2355
|
-
) {
|
2356
|
-
stylesObj = bodyNode.argument;
|
2357
|
-
}
|
2358
|
-
});
|
2359
|
-
return stylesObj;
|
2360
|
-
}
|
2361
|
-
}
|
2362
|
-
}
|
2363
|
-
break;
|
2364
|
-
}
|
2365
|
-
}
|
2366
|
-
|
2367
|
-
var classNaming = {
|
2368
|
-
meta: {
|
2369
|
-
type: 'problem'
|
2370
|
-
},
|
2371
|
-
create: function rule(context) {
|
2372
|
-
return {
|
2373
|
-
CallExpression(node) {
|
2374
|
-
const stylesObj = getStyesObj(node);
|
2375
|
-
if (stylesObj === undefined) {
|
2376
|
-
return;
|
2377
|
-
}
|
2378
|
-
stylesObj.properties.forEach(property => {
|
2379
|
-
if (property.computed) {
|
2380
|
-
return;
|
2381
|
-
}
|
2382
|
-
if (
|
2383
|
-
property.type === 'ExperimentalSpreadProperty' ||
|
2384
|
-
property.type === 'SpreadElement'
|
2385
|
-
) {
|
2386
|
-
return;
|
2387
|
-
}
|
2388
|
-
const className = property.key.value || property.key.name;
|
2389
|
-
if (!eslintUtils.isCamelCase(className)) {
|
2390
|
-
context.report({
|
2391
|
-
node: property,
|
2392
|
-
message: `Class \`${className}\` must be camelCase in TSS.`
|
2393
|
-
});
|
2394
|
-
}
|
2395
|
-
});
|
2396
|
-
}
|
2397
|
-
};
|
2398
|
-
}
|
2399
|
-
};
|
2400
|
-
|
2401
|
-
var noColorValue = {
|
2402
|
-
meta: {
|
2403
|
-
type: 'problem',
|
2404
|
-
docs: {
|
2405
|
-
description:
|
2406
|
-
'Enforce the use of color variables instead of color codes within TSS'
|
2407
|
-
}
|
2408
|
-
},
|
2409
|
-
create: function (context) {
|
2410
|
-
const parserOptions = context.parserOptions;
|
2411
|
-
if (!parserOptions || !parserOptions.project) {
|
2412
|
-
return {};
|
2413
|
-
}
|
2414
|
-
return {
|
2415
|
-
CallExpression(node) {
|
2416
|
-
const stylesObj = getStyesObj(node);
|
2417
|
-
if (!stylesObj) {
|
2418
|
-
return;
|
2419
|
-
}
|
2420
|
-
function checkColorLiteral(value) {
|
2421
|
-
if (value.type === 'Literal' && typeof value.value === 'string') {
|
2422
|
-
const colorCodePattern =
|
2423
|
-
/#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgb\?\(\s*(\d{1,3}\s*,\s*){2}\d{1,3}(?:\s*,\s*\d*(?:\.\d+)?)?\s*\)/g;
|
2424
|
-
const isColorCode = colorCodePattern.test(value.value);
|
2425
|
-
if (isColorCode) {
|
2426
|
-
context.report({
|
2427
|
-
node: value,
|
2428
|
-
message: 'Use color variables instead of color codes in TSS.'
|
2429
|
-
});
|
2430
|
-
}
|
2431
|
-
}
|
2432
|
-
}
|
2433
|
-
function loopStylesObj(obj) {
|
2434
|
-
if (obj && obj.type === 'ObjectExpression') {
|
2435
|
-
obj.properties.forEach(property => {
|
2436
|
-
if (property.type === 'Property' && property.value) {
|
2437
|
-
if (property.value.type === 'ObjectExpression') {
|
2438
|
-
loopStylesObj(property.value);
|
2439
|
-
} else {
|
2440
|
-
checkColorLiteral(property.value);
|
2441
|
-
}
|
2442
|
-
}
|
2443
|
-
});
|
2444
|
-
}
|
2445
|
-
}
|
2446
|
-
loopStylesObj(stylesObj);
|
2447
|
-
}
|
2448
|
-
};
|
2449
|
-
}
|
2450
|
-
};
|
2451
|
-
|
2452
|
-
var unusedClasses = {
|
2453
|
-
meta: {
|
2454
|
-
type: 'problem'
|
2455
|
-
},
|
2456
|
-
create: function rule(context) {
|
2457
|
-
const usedClasses = {};
|
2458
|
-
const definedClasses = {};
|
2459
|
-
return {
|
2460
|
-
CallExpression(node) {
|
2461
|
-
const stylesObj = getStyesObj(node);
|
2462
|
-
if (stylesObj === undefined) {
|
2463
|
-
return;
|
2464
|
-
}
|
2465
|
-
stylesObj.properties.forEach(property => {
|
2466
|
-
if (property.computed) {
|
2467
|
-
return;
|
2468
|
-
}
|
2469
|
-
if (
|
2470
|
-
property.type === 'ExperimentalSpreadProperty' ||
|
2471
|
-
property.type === 'SpreadElement'
|
2472
|
-
) {
|
2473
|
-
return;
|
2474
|
-
}
|
2475
|
-
definedClasses[property.key.value || property.key.name] = property;
|
2476
|
-
});
|
2477
|
-
},
|
2478
|
-
MemberExpression(node) {
|
2479
|
-
if (
|
2480
|
-
node.object.type === 'Identifier' &&
|
2481
|
-
node.object.name === 'classes'
|
2482
|
-
) {
|
2483
|
-
const whichClass = getBasicIdentifier(node.property);
|
2484
|
-
if (whichClass) {
|
2485
|
-
usedClasses[whichClass] = true;
|
2486
|
-
}
|
2487
|
-
return;
|
2488
|
-
}
|
2489
|
-
const classIdentifier = getBasicIdentifier(node.property);
|
2490
|
-
if (!classIdentifier) {
|
2491
|
-
return;
|
2492
|
-
}
|
2493
|
-
if (classIdentifier !== 'classes') {
|
2494
|
-
return;
|
2495
|
-
}
|
2496
|
-
const { parent } = node;
|
2497
|
-
if (parent.type !== 'MemberExpression') {
|
2498
|
-
return;
|
2499
|
-
}
|
2500
|
-
if (
|
2501
|
-
node.object.object &&
|
2502
|
-
node.object.object.type !== 'ThisExpression'
|
2503
|
-
) {
|
2504
|
-
return;
|
2505
|
-
}
|
2506
|
-
const propsIdentifier = getBasicIdentifier(parent.object);
|
2507
|
-
if (propsIdentifier && propsIdentifier !== 'props') {
|
2508
|
-
return;
|
2509
|
-
}
|
2510
|
-
if (!propsIdentifier && parent.object.type !== 'MemberExpression') {
|
2511
|
-
return;
|
2512
|
-
}
|
2513
|
-
if (parent.parent.type === 'MemberExpression') {
|
2514
|
-
return;
|
2515
|
-
}
|
2516
|
-
const parentClassIdentifier = getBasicIdentifier(parent.property);
|
2517
|
-
if (parentClassIdentifier) {
|
2518
|
-
usedClasses[parentClassIdentifier] = true;
|
2519
|
-
}
|
2520
|
-
},
|
2521
|
-
'Program:exit': () => {
|
2522
|
-
Object.keys(definedClasses).forEach(definedClassKey => {
|
2523
|
-
if (!usedClasses[definedClassKey]) {
|
2524
|
-
context.report({
|
2525
|
-
node: definedClasses[definedClassKey],
|
2526
|
-
message: `Class \`${definedClassKey}\` is unused`
|
2527
|
-
});
|
2528
|
-
}
|
2529
|
-
});
|
2530
|
-
}
|
2531
|
-
};
|
2532
|
-
}
|
2533
|
-
};
|
2534
|
-
|
2535
2535
|
var ruleFiles = /*#__PURE__*/Object.freeze({
|
2536
2536
|
__proto__: null,
|
2537
2537
|
rules_import_enforce_icon_alias: enforceIconAlias,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@agilebot/eslint-plugin",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.1",
|
4
4
|
"description": "Agilebot's ESLint plugin",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -18,9 +18,9 @@
|
|
18
18
|
"node": "^18.18.0 || >=20.0.0"
|
19
19
|
},
|
20
20
|
"dependencies": {
|
21
|
-
"@typescript-eslint/utils": "
|
21
|
+
"@typescript-eslint/utils": "~7.7.0",
|
22
22
|
"eslint-plugin-react": "^7.34.1",
|
23
|
-
"@agilebot/eslint-utils": "0.
|
23
|
+
"@agilebot/eslint-utils": "0.3.1"
|
24
24
|
},
|
25
25
|
"peerDependencies": {
|
26
26
|
"eslint": "^7.0.0 || ^8.0.0"
|