Skip to content

Commit

Permalink
feat: #RWEB_0041 - Do not modify the DOM when traversing it
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Apr 1, 2024
1 parent 3de82e0 commit 903911b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/bonnes-pratiques/01-bp-greenit.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ order: 300
- [ ] Limiter les fichiers de feuilles de style (<=10)
- [x] Utiliser HTTP/2 au lieu de HTTP/1
- [ ] Utiliser des polices de caractères standard
- [x] Ne pas faire de modification du DOM lorsqu’on le traverse
1 change: 1 addition & 0 deletions examples/simple-text-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"lhei:bp_0070": "node lighthouse-plugin-ecoindex/cli/index.js collect -u https://www.marmiton.org/ -o json -o html --audit-category=lighthouse-plugin-ecoindex",
"lhei:bp_0095": "node lighthouse-plugin-ecoindex/cli/index.js collect -u https://spie.com/en/journalists/profile-key-figures/ -o json -o html --audit-category=lighthouse-plugin-ecoindex",
"lhei:bp_0078": "node lighthouse-plugin-ecoindex/cli/index.js collect -u https://spie.com/en/journalists/profile-key-figures/ -o json -o html --audit-category=lighthouse-plugin-ecoindex",
"lhei:bp_0041": "node lighthouse-plugin-ecoindex/cli/index.js collect -u https://www.marmiton.org/ -o json -o html --audit-category=lighthouse-plugin-ecoindex",
"serve": "npx http-server -o reports --no-dotfiles"
},
"keywords": [],
Expand Down
29 changes: 29 additions & 0 deletions lighthouse-plugin-ecoindex/audits/bp/no-document-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import NoDocWriteAudit from 'lighthouse/core/audits/dobetterweb/no-document-write.js'
import ViolationAudit from 'lighthouse/core/audits/violation-audit.js'
import refsURLS from './refs-urls.js'

class NoDocWriteCustomAudit extends ViolationAudit {
static get meta() {
const meta = NoDocWriteAudit.meta

return {
...meta,
id: 'bp-no-document-write',
title: '#RWEB_0041 - Do not modify the DOM when traversing it',
failureTitle: '#RWEB_0041 - DOM modified.',
description: `Modifying the DOM (Document Object Model) when traversing it can lead to situations where the loop becomes very resource-hungry, particularly in terms of CPU cycles. Indeed, if you add elements while traversing it, you may generate an infinite loop that will consume a large amount of resources. This type of modification is therefore strongly discouraged. [See #RWEB_0041](${refsURLS.rweb.bp_0041.en})`,
}
}

static audit(artifacts, context) {
return NoDocWriteAudit.audit(artifacts, context)
}
}

export default NoDocWriteCustomAudit
4 changes: 4 additions & 0 deletions lighthouse-plugin-ecoindex/audits/bp/refs-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@ export default {
fr: 'https://ref.greenit.fr/rweb/fr/fiches/rweb_0078-compresser-les-fichiers-css-javascript-html-et-svg.html',
en: 'https://ref.greenit.fr/rweb/fr/fiches/rweb_0078-compresser-les-fichiers-css-javascript-html-et-svg.html',
},
bp_0041: {
fr: 'https://ref.greenit.fr/rweb/fr/fiches/rweb_0041-ne-pas-faire-de-modification-du-dom-lorsquon-le-traverse.html',
en: 'https://ref.greenit.fr/rweb/fr/fiches/rweb_0041-ne-pas-faire-de-modification-du-dom-lorsquon-le-traverse.html',
},
},
}
8 changes: 8 additions & 0 deletions lighthouse-plugin-ecoindex/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export default {
{
path: 'lighthouse-plugin-ecoindex/audits/bp/redirects.js',
},
{
path: 'lighthouse-plugin-ecoindex/audits/bp/no-document-write.js',
},
{
path: 'lighthouse-plugin-ecoindex/audits/bp/uses-text-compression.js',
},
Expand Down Expand Up @@ -130,6 +133,11 @@ export default {
weight: 0,
group: 'best-practices',
},
{
id: 'bp-no-document-write',
weight: 0,
group: 'best-practices',
},
{ id: 'bp-thegreenwebfoundation', weight: 0, group: 'other-practices' },
],
},
Expand Down

0 comments on commit 903911b

Please sign in to comment.