@eddacraft/anvil-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +14 -0
- package/dist/antipattern/index.d.ts +11 -0
- package/dist/antipattern/index.d.ts.map +1 -0
- package/dist/antipattern/index.js +31 -0
- package/dist/antipattern/patterns-css.d.ts +17 -0
- package/dist/antipattern/patterns-css.d.ts.map +1 -0
- package/dist/antipattern/patterns-css.js +72 -0
- package/dist/antipattern/patterns-html.d.ts +21 -0
- package/dist/antipattern/patterns-html.d.ts.map +1 -0
- package/dist/antipattern/patterns-html.js +139 -0
- package/dist/antipattern/patterns.d.ts +72 -0
- package/dist/antipattern/patterns.d.ts.map +1 -0
- package/dist/antipattern/patterns.js +301 -0
- package/dist/antipattern/scanner.d.ts +32 -0
- package/dist/antipattern/scanner.d.ts.map +1 -0
- package/dist/antipattern/scanner.js +89 -0
- package/dist/antipattern/types.d.ts +318 -0
- package/dist/antipattern/types.d.ts.map +1 -0
- package/dist/antipattern/types.js +278 -0
- package/dist/architecture/analyzer.d.ts +123 -0
- package/dist/architecture/analyzer.d.ts.map +1 -0
- package/dist/architecture/analyzer.js +321 -0
- package/dist/architecture/baseline.d.ts +112 -0
- package/dist/architecture/baseline.d.ts.map +1 -0
- package/dist/architecture/baseline.js +245 -0
- package/dist/architecture/compiler.d.ts +24 -0
- package/dist/architecture/compiler.d.ts.map +1 -0
- package/dist/architecture/compiler.js +57 -0
- package/dist/architecture/context.d.ts +129 -0
- package/dist/architecture/context.d.ts.map +1 -0
- package/dist/architecture/context.js +116 -0
- package/dist/architecture/dc-generator.d.ts +9 -0
- package/dist/architecture/dc-generator.d.ts.map +1 -0
- package/dist/architecture/dc-generator.js +220 -0
- package/dist/architecture/definition-schema.d.ts +128 -0
- package/dist/architecture/definition-schema.d.ts.map +1 -0
- package/dist/architecture/definition-schema.js +94 -0
- package/dist/architecture/edge-detector-html.d.ts +6 -0
- package/dist/architecture/edge-detector-html.d.ts.map +1 -0
- package/dist/architecture/edge-detector-html.js +5 -0
- package/dist/architecture/edge-detector-web.d.ts +32 -0
- package/dist/architecture/edge-detector-web.d.ts.map +1 -0
- package/dist/architecture/edge-detector-web.js +133 -0
- package/dist/architecture/edge-detector.d.ts +116 -0
- package/dist/architecture/edge-detector.d.ts.map +1 -0
- package/dist/architecture/edge-detector.js +229 -0
- package/dist/architecture/entry-detector.d.ts +44 -0
- package/dist/architecture/entry-detector.d.ts.map +1 -0
- package/dist/architecture/entry-detector.js +263 -0
- package/dist/architecture/index.d.ts +21 -0
- package/dist/architecture/index.d.ts.map +1 -0
- package/dist/architecture/index.js +48 -0
- package/dist/architecture/layer-detector.d.ts +60 -0
- package/dist/architecture/layer-detector.d.ts.map +1 -0
- package/dist/architecture/layer-detector.js +331 -0
- package/dist/architecture/rego-generator.d.ts +25 -0
- package/dist/architecture/rego-generator.d.ts.map +1 -0
- package/dist/architecture/rego-generator.js +229 -0
- package/dist/architecture/templates/index.d.ts +39 -0
- package/dist/architecture/templates/index.d.ts.map +1 -0
- package/dist/architecture/templates/index.js +124 -0
- package/dist/architecture/types.d.ts +280 -0
- package/dist/architecture/types.d.ts.map +1 -0
- package/dist/architecture/types.js +269 -0
- package/dist/architecture/yaml-parser.d.ts +13 -0
- package/dist/architecture/yaml-parser.d.ts.map +1 -0
- package/dist/architecture/yaml-parser.js +234 -0
- package/dist/config/constants.d.ts +9 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +20 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +8 -0
- package/dist/config/loader.d.ts +41 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +76 -0
- package/dist/config/nudge-config.d.ts +35 -0
- package/dist/config/nudge-config.d.ts.map +1 -0
- package/dist/config/nudge-config.js +34 -0
- package/dist/config/types.d.ts +30 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +4 -0
- package/dist/contracts/index.d.ts +14 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +13 -0
- package/dist/contracts/schemas/aps.schema.d.ts +269 -0
- package/dist/contracts/schemas/aps.schema.d.ts.map +1 -0
- package/dist/contracts/schemas/aps.schema.js +183 -0
- package/dist/contracts/schemas/index.d.ts +12 -0
- package/dist/contracts/schemas/index.d.ts.map +1 -0
- package/dist/contracts/schemas/index.js +14 -0
- package/dist/contracts/schemas/json-schema.d.ts +14 -0
- package/dist/contracts/schemas/json-schema.d.ts.map +1 -0
- package/dist/contracts/schemas/json-schema.js +31 -0
- package/dist/contracts/schemas/warning.schema.d.ts +171 -0
- package/dist/contracts/schemas/warning.schema.d.ts.map +1 -0
- package/dist/contracts/schemas/warning.schema.js +123 -0
- package/dist/contracts/types/gate.types.d.ts +194 -0
- package/dist/contracts/types/gate.types.d.ts.map +1 -0
- package/dist/contracts/types/gate.types.js +19 -0
- package/dist/contracts/types/index.d.ts +9 -0
- package/dist/contracts/types/index.d.ts.map +1 -0
- package/dist/contracts/types/index.js +8 -0
- package/dist/crypto/hash.d.ts +47 -0
- package/dist/crypto/hash.d.ts.map +1 -0
- package/dist/crypto/hash.js +110 -0
- package/dist/crypto/index.d.ts +7 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +6 -0
- package/dist/drift/index.d.ts +6 -0
- package/dist/drift/index.d.ts.map +1 -0
- package/dist/drift/index.js +5 -0
- package/dist/drift/report-generator.d.ts +21 -0
- package/dist/drift/report-generator.d.ts.map +1 -0
- package/dist/drift/report-generator.js +240 -0
- package/dist/drift/snapshot-capture.d.ts +26 -0
- package/dist/drift/snapshot-capture.d.ts.map +1 -0
- package/dist/drift/snapshot-capture.js +195 -0
- package/dist/drift/snapshot-compare.d.ts +50 -0
- package/dist/drift/snapshot-compare.d.ts.map +1 -0
- package/dist/drift/snapshot-compare.js +142 -0
- package/dist/drift/snapshot-schema.d.ts +197 -0
- package/dist/drift/snapshot-schema.d.ts.map +1 -0
- package/dist/drift/snapshot-schema.js +193 -0
- package/dist/drift/snapshot-storage.d.ts +25 -0
- package/dist/drift/snapshot-storage.d.ts.map +1 -0
- package/dist/drift/snapshot-storage.js +179 -0
- package/dist/explain/antipattern-explainer.d.ts +4 -0
- package/dist/explain/antipattern-explainer.d.ts.map +1 -0
- package/dist/explain/antipattern-explainer.js +196 -0
- package/dist/explain/boundary-explainer.d.ts +5 -0
- package/dist/explain/boundary-explainer.d.ts.map +1 -0
- package/dist/explain/boundary-explainer.js +261 -0
- package/dist/explain/explain-service.d.ts +19 -0
- package/dist/explain/explain-service.d.ts.map +1 -0
- package/dist/explain/explain-service.js +106 -0
- package/dist/explain/index.d.ts +7 -0
- package/dist/explain/index.d.ts.map +1 -0
- package/dist/explain/index.js +5 -0
- package/dist/explain/template-loader.d.ts +9 -0
- package/dist/explain/template-loader.d.ts.map +1 -0
- package/dist/explain/template-loader.js +51 -0
- package/dist/explain/types.d.ts +46 -0
- package/dist/explain/types.d.ts.map +1 -0
- package/dist/explain/types.js +31 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/provenance/collector.d.ts +86 -0
- package/dist/provenance/collector.d.ts.map +1 -0
- package/dist/provenance/collector.js +425 -0
- package/dist/provenance/git-ai-standard/git-notes.d.ts +85 -0
- package/dist/provenance/git-ai-standard/git-notes.d.ts.map +1 -0
- package/dist/provenance/git-ai-standard/git-notes.js +292 -0
- package/dist/provenance/git-ai-standard/index.d.ts +44 -0
- package/dist/provenance/git-ai-standard/index.d.ts.map +1 -0
- package/dist/provenance/git-ai-standard/index.js +47 -0
- package/dist/provenance/git-ai-standard/serializer.d.ts +54 -0
- package/dist/provenance/git-ai-standard/serializer.d.ts.map +1 -0
- package/dist/provenance/git-ai-standard/serializer.js +224 -0
- package/dist/provenance/git-ai-standard/session.d.ts +51 -0
- package/dist/provenance/git-ai-standard/session.d.ts.map +1 -0
- package/dist/provenance/git-ai-standard/session.js +118 -0
- package/dist/provenance/git-ai-standard/types.d.ts +173 -0
- package/dist/provenance/git-ai-standard/types.d.ts.map +1 -0
- package/dist/provenance/git-ai-standard/types.js +109 -0
- package/dist/provenance/index.d.ts +5 -0
- package/dist/provenance/index.d.ts.map +1 -0
- package/dist/provenance/index.js +6 -0
- package/dist/provenance/store.d.ts +83 -0
- package/dist/provenance/store.d.ts.map +1 -0
- package/dist/provenance/store.js +248 -0
- package/dist/provenance/types.d.ts +160 -0
- package/dist/provenance/types.d.ts.map +1 -0
- package/dist/provenance/types.js +112 -0
- package/dist/suppression/index.d.ts +4 -0
- package/dist/suppression/index.d.ts.map +1 -0
- package/dist/suppression/index.js +3 -0
- package/dist/suppression/parser.d.ts +31 -0
- package/dist/suppression/parser.d.ts.map +1 -0
- package/dist/suppression/parser.js +219 -0
- package/dist/suppression/service.d.ts +29 -0
- package/dist/suppression/service.d.ts.map +1 -0
- package/dist/suppression/service.js +132 -0
- package/dist/suppression/store.d.ts +61 -0
- package/dist/suppression/store.d.ts.map +1 -0
- package/dist/suppression/store.js +169 -0
- package/dist/utils/debug.d.ts +48 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +100 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/path-safety.d.ts +21 -0
- package/dist/utils/path-safety.d.ts.map +1 -0
- package/dist/utils/path-safety.js +49 -0
- package/dist/utils/severity.d.ts +37 -0
- package/dist/utils/severity.d.ts.map +1 -0
- package/dist/utils/severity.js +22 -0
- package/dist/validation/aps-validator.d.ts +66 -0
- package/dist/validation/aps-validator.d.ts.map +1 -0
- package/dist/validation/aps-validator.js +173 -0
- package/dist/validation/errors.d.ts +52 -0
- package/dist/validation/errors.d.ts.map +1 -0
- package/dist/validation/errors.js +115 -0
- package/dist/validation/index.d.ts +8 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +13 -0
- package/dist/warnings/index.d.ts +2 -0
- package/dist/warnings/index.d.ts.map +1 -0
- package/dist/warnings/index.js +1 -0
- package/dist/warnings/warning-id.d.ts +180 -0
- package/dist/warnings/warning-id.d.ts.map +1 -0
- package/dist/warnings/warning-id.js +257 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) 2026 EddaCraft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
PROPRIETARY AND CONFIDENTIAL
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are the
|
|
6
|
+
exclusive property of EddaCraft. Unauthorised copying, modification,
|
|
7
|
+
distribution, or use of this Software, via any medium, is strictly prohibited
|
|
8
|
+
without the express written permission of EddaCraft.
|
|
9
|
+
|
|
10
|
+
The Software is provided for evaluation and testing purposes only to authorised
|
|
11
|
+
beta testers. No licence is granted to use, copy, modify, or distribute the
|
|
12
|
+
Software for any other purpose.
|
|
13
|
+
|
|
14
|
+
For licensing enquiries, contact: legal@eddacraft.com
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-pattern detection module
|
|
3
|
+
*
|
|
4
|
+
* Provides detection of code anti-patterns and architecture boundary violations.
|
|
5
|
+
*/
|
|
6
|
+
export { LocationSchema, type Location, DriftSchema, type Drift, SuppressionSchema, type Suppression, WarningCategorySchema, type WarningCategory, WarningSeveritySchema, type WarningSeverity, ConfidenceSchema, type Confidence, WarningSchema, type Warning, RegexDetectionConfigSchema, type RegexDetectionConfig, AstDetectionConfigSchema, type AstDetectionConfig, DetectionConfigSchema, type DetectionConfig, AntiPatternSchema, type AntiPattern, WarningResultSchema, type WarningResult, type WarningSummary, SuppressionRecordSchema, type SuppressionRecord, createWarningFingerprint, isBlockingWarning, countBySeverity, createWarningResult, validateWarningResultConsistency, } from './types.js';
|
|
7
|
+
export { PATTERNS, type PatternCategory, getPattern, getPatternsByCategory, getEnabledPatterns, getDefaultPatterns, getPatternIds, isValidPatternId, } from './patterns.js';
|
|
8
|
+
export { HTML_PATTERNS } from './patterns-html.js';
|
|
9
|
+
export { CSS_PATTERNS } from './patterns-css.js';
|
|
10
|
+
export { type ScanOptions, type ScanResult, scanFile, scanFiles } from './scanner.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/antipattern/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAEL,cAAc,EACd,KAAK,QAAQ,EAEb,WAAW,EACX,KAAK,KAAK,EAEV,iBAAiB,EACjB,KAAK,WAAW,EAEhB,qBAAqB,EACrB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,eAAe,EACpB,gBAAgB,EAChB,KAAK,UAAU,EACf,aAAa,EACb,KAAK,OAAO,EAEZ,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,qBAAqB,EACrB,KAAK,eAAe,EACpB,iBAAiB,EACjB,KAAK,WAAW,EAEhB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,cAAc,EAEnB,uBAAuB,EACvB,KAAK,iBAAiB,EAEtB,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,gCAAgC,GACjC,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,QAAQ,EACR,KAAK,eAAe,EACpB,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-pattern detection module
|
|
3
|
+
*
|
|
4
|
+
* Provides detection of code anti-patterns and architecture boundary violations.
|
|
5
|
+
*/
|
|
6
|
+
// Types and schemas
|
|
7
|
+
export {
|
|
8
|
+
// Location
|
|
9
|
+
LocationSchema,
|
|
10
|
+
// Drift
|
|
11
|
+
DriftSchema,
|
|
12
|
+
// Suppression
|
|
13
|
+
SuppressionSchema,
|
|
14
|
+
// Warning
|
|
15
|
+
WarningCategorySchema, WarningSeveritySchema, ConfidenceSchema, WarningSchema,
|
|
16
|
+
// Anti-pattern definition
|
|
17
|
+
RegexDetectionConfigSchema, AstDetectionConfigSchema, DetectionConfigSchema, AntiPatternSchema,
|
|
18
|
+
// Results
|
|
19
|
+
WarningResultSchema,
|
|
20
|
+
// Suppression records
|
|
21
|
+
SuppressionRecordSchema,
|
|
22
|
+
// Utilities
|
|
23
|
+
createWarningFingerprint, isBlockingWarning, countBySeverity, createWarningResult, validateWarningResultConsistency, } from './types.js';
|
|
24
|
+
// Pattern catalogue
|
|
25
|
+
export { PATTERNS, getPattern, getPatternsByCategory, getEnabledPatterns, getDefaultPatterns, getPatternIds, isValidPatternId, } from './patterns.js';
|
|
26
|
+
// HTML patterns
|
|
27
|
+
export { HTML_PATTERNS } from './patterns-html.js';
|
|
28
|
+
// CSS patterns
|
|
29
|
+
export { CSS_PATTERNS } from './patterns-css.js';
|
|
30
|
+
// Scanner
|
|
31
|
+
export { scanFile, scanFiles } from './scanner.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Anti-pattern Definitions
|
|
3
|
+
*
|
|
4
|
+
* Detects common CSS anti-patterns:
|
|
5
|
+
* - AP-012: !important usage
|
|
6
|
+
* - AP-013: CSS @import (performance concern)
|
|
7
|
+
*
|
|
8
|
+
* All patterns are opt-in by default (D-001).
|
|
9
|
+
*
|
|
10
|
+
* @module antipattern/patterns-css
|
|
11
|
+
*/
|
|
12
|
+
import type { AntiPattern } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* All CSS anti-patterns
|
|
15
|
+
*/
|
|
16
|
+
export declare const CSS_PATTERNS: readonly AntiPattern[];
|
|
17
|
+
//# sourceMappingURL=patterns-css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns-css.d.ts","sourceRoot":"","sources":["../../src/antipattern/patterns-css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAmE9C;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,WAAW,EAAiD,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Anti-pattern Definitions
|
|
3
|
+
*
|
|
4
|
+
* Detects common CSS anti-patterns:
|
|
5
|
+
* - AP-012: !important usage
|
|
6
|
+
* - AP-013: CSS @import (performance concern)
|
|
7
|
+
*
|
|
8
|
+
* All patterns are opt-in by default (D-001).
|
|
9
|
+
*
|
|
10
|
+
* @module antipattern/patterns-css
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* AP-012: !important in CSS
|
|
14
|
+
*
|
|
15
|
+
* Detects usage of `!important` in CSS declarations.
|
|
16
|
+
* Overuse of !important creates specificity wars and makes CSS harder to maintain.
|
|
17
|
+
*/
|
|
18
|
+
const AP012_IMPORTANT = {
|
|
19
|
+
id: 'AP-012',
|
|
20
|
+
name: '!important in CSS',
|
|
21
|
+
category: 'css',
|
|
22
|
+
severity: 'warning',
|
|
23
|
+
confidence: 'high',
|
|
24
|
+
detection: {
|
|
25
|
+
type: 'regex',
|
|
26
|
+
pattern: String.raw `!\s*important`,
|
|
27
|
+
},
|
|
28
|
+
title: '!important used in CSS',
|
|
29
|
+
explanation: 'Using !important overrides all other specificity rules, creating maintenance headaches. ' +
|
|
30
|
+
'It often indicates specificity wars or architectural issues in CSS.',
|
|
31
|
+
suggestion: 'Increase selector specificity naturally, restructure CSS to avoid conflicts, ' +
|
|
32
|
+
'or use CSS layers (@layer) for better cascade control.',
|
|
33
|
+
nudge: "Don't use `!important` — it breaks the cascade and makes styles nearly " +
|
|
34
|
+
'impossible to override. Instead, increase the specificity of your ' +
|
|
35
|
+
'selector or restructure your CSS to avoid the conflict.',
|
|
36
|
+
fileExtensions: ['.css', '.scss', '.less'],
|
|
37
|
+
allowlist: ['**/reset.css', '**/normalize.css'],
|
|
38
|
+
enabled: true,
|
|
39
|
+
optIn: true,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* AP-013: CSS @import
|
|
43
|
+
*
|
|
44
|
+
* Detects usage of CSS `@import` which causes sequential loading.
|
|
45
|
+
* This is a performance concern, not a bug.
|
|
46
|
+
*/
|
|
47
|
+
const AP013_CSS_IMPORT = {
|
|
48
|
+
id: 'AP-013',
|
|
49
|
+
name: 'CSS @import',
|
|
50
|
+
category: 'css',
|
|
51
|
+
severity: 'info',
|
|
52
|
+
confidence: 'high',
|
|
53
|
+
detection: {
|
|
54
|
+
type: 'regex',
|
|
55
|
+
pattern: String.raw `@import\s+(?:url\()?["']`,
|
|
56
|
+
},
|
|
57
|
+
title: 'CSS @import causes sequential loading',
|
|
58
|
+
explanation: 'CSS @import causes browsers to load stylesheets sequentially rather than in parallel, ' +
|
|
59
|
+
'which increases page load time. Each @import blocks rendering until the imported file loads.',
|
|
60
|
+
suggestion: 'Use <link> tags in HTML for parallel loading, or use a CSS bundler ' +
|
|
61
|
+
'(PostCSS, Sass, etc.) to inline imports at build time.',
|
|
62
|
+
nudge: 'Replace this CSS `@import` with a `<link>` tag in your HTML. `@import` ' +
|
|
63
|
+
'blocks parallel downloads and slows page load. Each `@import` creates a ' +
|
|
64
|
+
'sequential request.',
|
|
65
|
+
fileExtensions: ['.css', '.scss', '.less'],
|
|
66
|
+
enabled: true,
|
|
67
|
+
optIn: true,
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* All CSS anti-patterns
|
|
71
|
+
*/
|
|
72
|
+
export const CSS_PATTERNS = [AP012_IMPORTANT, AP013_CSS_IMPORT];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML Anti-pattern Definitions
|
|
3
|
+
*
|
|
4
|
+
* Detects common HTML anti-patterns:
|
|
5
|
+
* - AP-008: Inline style attributes
|
|
6
|
+
* - AP-009: Inline script blocks
|
|
7
|
+
* - AP-010: Inline event handlers
|
|
8
|
+
* - AP-011: Deprecated HTML tags
|
|
9
|
+
*
|
|
10
|
+
* All patterns are opt-in by default (D-001).
|
|
11
|
+
* All patterns include email template allowlist since HTML emails
|
|
12
|
+
* legitimately use inline styles and scripts.
|
|
13
|
+
*
|
|
14
|
+
* @module antipattern/patterns-html
|
|
15
|
+
*/
|
|
16
|
+
import type { AntiPattern } from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* All HTML anti-patterns
|
|
19
|
+
*/
|
|
20
|
+
export declare const HTML_PATTERNS: readonly AntiPattern[];
|
|
21
|
+
//# sourceMappingURL=patterns-html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns-html.d.ts","sourceRoot":"","sources":["../../src/antipattern/patterns-html.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAqI9C;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAKtC,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML Anti-pattern Definitions
|
|
3
|
+
*
|
|
4
|
+
* Detects common HTML anti-patterns:
|
|
5
|
+
* - AP-008: Inline style attributes
|
|
6
|
+
* - AP-009: Inline script blocks
|
|
7
|
+
* - AP-010: Inline event handlers
|
|
8
|
+
* - AP-011: Deprecated HTML tags
|
|
9
|
+
*
|
|
10
|
+
* All patterns are opt-in by default (D-001).
|
|
11
|
+
* All patterns include email template allowlist since HTML emails
|
|
12
|
+
* legitimately use inline styles and scripts.
|
|
13
|
+
*
|
|
14
|
+
* @module antipattern/patterns-html
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* AP-008: Inline style attribute
|
|
18
|
+
*
|
|
19
|
+
* Detects `style="..."` attributes in HTML elements.
|
|
20
|
+
* Inline styles hinder maintainability and prevent caching of CSS.
|
|
21
|
+
*/
|
|
22
|
+
const AP008_INLINE_STYLE = {
|
|
23
|
+
id: 'AP-008',
|
|
24
|
+
name: 'Inline style attribute',
|
|
25
|
+
category: 'html',
|
|
26
|
+
severity: 'warning',
|
|
27
|
+
confidence: 'high',
|
|
28
|
+
detection: {
|
|
29
|
+
type: 'regex',
|
|
30
|
+
pattern: String.raw `style\s*=\s*["']`,
|
|
31
|
+
},
|
|
32
|
+
title: 'Inline style attribute found',
|
|
33
|
+
explanation: 'Inline styles mix presentation with structure, making CSS harder to maintain, ' +
|
|
34
|
+
'override, and cache. They also increase HTML file size.',
|
|
35
|
+
suggestion: 'Move styles to an external CSS file or use CSS classes. ' +
|
|
36
|
+
'For dynamic styles, use CSS custom properties or a CSS-in-JS solution.',
|
|
37
|
+
nudge: "Move this inline style to a CSS class. Inline styles can't be overridden " +
|
|
38
|
+
'by stylesheets, break consistency, and make maintenance harder. Define a ' +
|
|
39
|
+
'class in your stylesheet and apply it instead.',
|
|
40
|
+
fileExtensions: ['.html', '.htm'],
|
|
41
|
+
allowlist: ['**/email/**'],
|
|
42
|
+
enabled: true,
|
|
43
|
+
optIn: true,
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* AP-009: Inline script block
|
|
47
|
+
*
|
|
48
|
+
* Detects `<script>` blocks with inline code (not just closing tags).
|
|
49
|
+
* Inline scripts bypass CSP and prevent caching.
|
|
50
|
+
*/
|
|
51
|
+
const AP009_INLINE_SCRIPT = {
|
|
52
|
+
id: 'AP-009',
|
|
53
|
+
name: 'Inline script block',
|
|
54
|
+
category: 'html',
|
|
55
|
+
severity: 'warning',
|
|
56
|
+
confidence: 'high',
|
|
57
|
+
detection: {
|
|
58
|
+
type: 'regex',
|
|
59
|
+
pattern: String.raw `<script(?:\s[^>]*)?>(?!\s*<\/script>)`,
|
|
60
|
+
},
|
|
61
|
+
title: 'Inline script block found',
|
|
62
|
+
explanation: 'Inline scripts bypass Content Security Policy (CSP), prevent browser caching, ' +
|
|
63
|
+
'and make code harder to test and maintain.',
|
|
64
|
+
suggestion: 'Move JavaScript to external .js files referenced with <script src="...">. ' +
|
|
65
|
+
'This enables caching, CSP compliance, and better separation of concerns.',
|
|
66
|
+
nudge: 'Move this script to an external `.js` file and reference it with ' +
|
|
67
|
+
'`<script src="...">`. Inline scripts cannot be cached, violate CSP ' +
|
|
68
|
+
'policies, and make code harder to test.',
|
|
69
|
+
fileExtensions: ['.html', '.htm'],
|
|
70
|
+
allowlist: ['**/email/**'],
|
|
71
|
+
enabled: true,
|
|
72
|
+
optIn: true,
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* AP-010: Inline event handler
|
|
76
|
+
*
|
|
77
|
+
* Detects `on*="..."` attributes like onclick, onload, etc.
|
|
78
|
+
* Inline handlers mix behavior with structure and bypass CSP.
|
|
79
|
+
*/
|
|
80
|
+
const AP010_INLINE_EVENT_HANDLER = {
|
|
81
|
+
id: 'AP-010',
|
|
82
|
+
name: 'Inline event handler',
|
|
83
|
+
category: 'html',
|
|
84
|
+
severity: 'warning',
|
|
85
|
+
confidence: 'high',
|
|
86
|
+
detection: {
|
|
87
|
+
type: 'regex',
|
|
88
|
+
pattern: String.raw `\bon\w+\s*=\s*["']`,
|
|
89
|
+
},
|
|
90
|
+
title: 'Inline event handler found',
|
|
91
|
+
explanation: 'Inline event handlers (onclick, onload, etc.) mix behavior with HTML structure, ' +
|
|
92
|
+
'bypass CSP, and make code harder to debug and maintain.',
|
|
93
|
+
suggestion: 'Use addEventListener() in external JavaScript files instead. ' +
|
|
94
|
+
'For frameworks, use the framework event binding syntax.',
|
|
95
|
+
nudge: 'Remove this inline event handler and use `addEventListener()` in an ' +
|
|
96
|
+
'external script instead. Inline handlers mix behaviour with markup and ' +
|
|
97
|
+
'are blocked by strict Content Security Policies.',
|
|
98
|
+
fileExtensions: ['.html', '.htm'],
|
|
99
|
+
allowlist: ['**/email/**'],
|
|
100
|
+
enabled: true,
|
|
101
|
+
optIn: true,
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* AP-011: Deprecated HTML tags
|
|
105
|
+
*
|
|
106
|
+
* Detects usage of deprecated HTML tags like <font>, <center>, <marquee>, etc.
|
|
107
|
+
* These tags are obsolete and should be replaced with CSS.
|
|
108
|
+
*/
|
|
109
|
+
const AP011_DEPRECATED_TAGS = {
|
|
110
|
+
id: 'AP-011',
|
|
111
|
+
name: 'Deprecated HTML tag',
|
|
112
|
+
category: 'html',
|
|
113
|
+
severity: 'warning',
|
|
114
|
+
confidence: 'high',
|
|
115
|
+
detection: {
|
|
116
|
+
type: 'regex',
|
|
117
|
+
pattern: String.raw `<(?:font|center|marquee|blink|big|strike)\b`,
|
|
118
|
+
},
|
|
119
|
+
title: 'Deprecated HTML tag used',
|
|
120
|
+
explanation: 'Deprecated HTML tags like <font>, <center>, and <marquee> are obsolete. ' +
|
|
121
|
+
'They may not render correctly in modern browsers and indicate outdated practices.',
|
|
122
|
+
suggestion: 'Replace deprecated tags with semantic HTML and CSS. ' +
|
|
123
|
+
'For example, use CSS text-align instead of <center>, and CSS font properties instead of <font>.',
|
|
124
|
+
nudge: 'Replace this deprecated HTML tag with its modern CSS equivalent. Use CSS ' +
|
|
125
|
+
'for visual presentation instead of presentational HTML elements.',
|
|
126
|
+
fileExtensions: ['.html', '.htm'],
|
|
127
|
+
allowlist: ['**/email/**'],
|
|
128
|
+
enabled: true,
|
|
129
|
+
optIn: true,
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* All HTML anti-patterns
|
|
133
|
+
*/
|
|
134
|
+
export const HTML_PATTERNS = [
|
|
135
|
+
AP008_INLINE_STYLE,
|
|
136
|
+
AP009_INLINE_SCRIPT,
|
|
137
|
+
AP010_INLINE_EVENT_HANDLER,
|
|
138
|
+
AP011_DEPRECATED_TAGS,
|
|
139
|
+
];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-pattern Catalogue
|
|
3
|
+
*
|
|
4
|
+
* Defines the built-in anti-patterns that Anvil detects. Each pattern has:
|
|
5
|
+
* - ID: Unique identifier (AP-001, AP-002, etc.)
|
|
6
|
+
* - Detection: Regex or AST-based detection method
|
|
7
|
+
* - Messaging: Title, explanation, and suggestion for warnings
|
|
8
|
+
* - Configuration: Severity, confidence, allowlist, threshold, etc.
|
|
9
|
+
*
|
|
10
|
+
* @module antipattern/patterns
|
|
11
|
+
*/
|
|
12
|
+
import type { AntiPattern } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* All built-in anti-patterns
|
|
15
|
+
*/
|
|
16
|
+
export declare const PATTERNS: readonly AntiPattern[];
|
|
17
|
+
/**
|
|
18
|
+
* Pattern categories for filtering
|
|
19
|
+
*/
|
|
20
|
+
export type PatternCategory = AntiPattern['category'];
|
|
21
|
+
/**
|
|
22
|
+
* Get a pattern by ID
|
|
23
|
+
*
|
|
24
|
+
* @param id - Pattern ID (e.g., 'AP-001')
|
|
25
|
+
* @returns The pattern definition, or undefined if not found
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const pattern = getPattern('AP-001');
|
|
30
|
+
* console.log(pattern?.name); // 'Broad eslint-disable'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function getPattern(id: string): AntiPattern | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Get all patterns in a category
|
|
36
|
+
*
|
|
37
|
+
* @param category - The category to filter by
|
|
38
|
+
* @returns Array of patterns in that category
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const escapeHatches = getPatternsByCategory('escape-hatch');
|
|
43
|
+
* console.log(escapeHatches.map(p => p.id)); // ['AP-001', 'AP-002']
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function getPatternsByCategory(category: PatternCategory): AntiPattern[];
|
|
47
|
+
/**
|
|
48
|
+
* Get all enabled patterns (respects enabled flag, not optIn)
|
|
49
|
+
*
|
|
50
|
+
* @returns Array of enabled patterns
|
|
51
|
+
*/
|
|
52
|
+
export declare function getEnabledPatterns(): AntiPattern[];
|
|
53
|
+
/**
|
|
54
|
+
* Get all default patterns (enabled and not opt-in)
|
|
55
|
+
*
|
|
56
|
+
* @returns Array of patterns that are enabled by default
|
|
57
|
+
*/
|
|
58
|
+
export declare function getDefaultPatterns(): AntiPattern[];
|
|
59
|
+
/**
|
|
60
|
+
* Get pattern IDs for all patterns
|
|
61
|
+
*
|
|
62
|
+
* @returns Array of pattern IDs
|
|
63
|
+
*/
|
|
64
|
+
export declare function getPatternIds(): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Check if a pattern ID is valid
|
|
67
|
+
*
|
|
68
|
+
* @param id - Pattern ID to check
|
|
69
|
+
* @returns true if the ID exists in the catalogue
|
|
70
|
+
*/
|
|
71
|
+
export declare function isValidPatternId(id: string): boolean;
|
|
72
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/antipattern/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAiP9C;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,WAAW,EAUjC,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;AAMtD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAE9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,WAAW,EAAE,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,WAAW,EAAE,CAElD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,WAAW,EAAE,CAElD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,EAAE,CAExC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEpD"}
|