Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prebid 9: Removing innerText & adding eslint rule #11531

Merged
merged 2 commits into from
May 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
11233 Removing innerText & adding eslint rule
  • Loading branch information
Marcin Komorski authored and Marcin Komorski committed May 22, 2024
commit 0e513963e376cf5d8482212469ff83043b385da3
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ module.exports = {
files: key + '/**/*.js',
rules: {
'prebid/validate-imports': ['error', allowedModules[key]],
'prebid/no-innerText': ['error', allowedModules[key]],
'no-restricted-globals': [
'error',
{
2 changes: 1 addition & 1 deletion modules/adhashBidAdapter.js
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ function brandSafety(badWords, maxScore) {
.replaceAll(/\s\s+/g, ' ')
.toLowerCase()
.trim();
const content = window.top.document.body.innerText.toLowerCase();
const content = window.top.document.body.textContent.toLowerCase();
// \p{L} matches a single unicode code point in the category 'letter'. Matches any kind of letter from any language.
const regexp = new RegExp('[\\p{L}]+', 'gu');
const wordsMatched = content.match(regexp);
2 changes: 1 addition & 1 deletion modules/idImportLibrary.js
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ function handleTargetElement() {

const targetElement = document.getElementById(conf.target);
if (targetElement) {
email = targetElement.innerText;
email = targetElement.textContent;

if (!email) {
_logInfo('Finding the email with observer');
54 changes: 54 additions & 0 deletions plugins/eslint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const _ = require('lodash');
const { flagErrors } = require('./validateImports.js');

module.exports = {
rules: {
'no-innerText': {
meta: {
docs: {
description: '.innerText property on DOM elements should not be used due to performance issues'
},
messages: {
noInnerText: 'Use of `.innerText` is not allowed. Use `.textContent` instead.',
}
},
create: function(context) {
return {
MemberExpression(node) {
if (node.property && node.property.name === 'innerText') {
context.report({
node: node.property,
messageId: 'noInnerText',
});
}
}
}
}
},
'validate-imports': {
meta: {
docs: {
description: 'validates module imports can be found without custom webpack resolvers, are in module whitelist, and not module entry points'
}
},
create: function(context) {
return {
"CallExpression[callee.name='require']"(node) {
let importPath = _.get(node, ['arguments', 0, 'value']);
if (importPath) {
flagErrors(context, node, importPath);
}
},
ImportDeclaration(node) {
let importPath = node.source.value.trim();
flagErrors(context, node, importPath);
},
'ExportNamedDeclaration[source]'(node) {
let importPath = node.source.value.trim();
flagErrors(context, node, importPath);
}
}
}
}
}
};
2 changes: 1 addition & 1 deletion plugins/eslint/package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "eslint-plugin-prebid",
"version": "1.0.0",
"description": "validates module imports can be found without custom webpack resolvers, are in module whitelist, and not module entry points",
"main": "validateImports.js",
"main": "index.js",
"author": "the prebid.js contributors",
"license": "Apache-2.0"
}
30 changes: 2 additions & 28 deletions plugins/eslint/validateImports.js
Original file line number Diff line number Diff line change
@@ -53,31 +53,5 @@ function flagErrors(context, node, importPath) {
}

module.exports = {
rules: {
'validate-imports': {
meta: {
docs: {
description: 'validates module imports can be found without custom webpack resolvers, are in module whitelist, and not module entry points'
}
},
create: function(context) {
return {
"CallExpression[callee.name='require']"(node) {
let importPath = _.get(node, ['arguments', 0, 'value']);
if (importPath) {
flagErrors(context, node, importPath);
}
},
ImportDeclaration(node) {
let importPath = node.source.value.trim();
flagErrors(context, node, importPath);
},
'ExportNamedDeclaration[source]'(node) {
let importPath = node.source.value.trim();
flagErrors(context, node, importPath);
}
}
}
}
}
};
flagErrors
}