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

Add test file for "No css animations" rule #8

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/avoid-high-accuracy-geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ function error(err) {
console.warn(err);
}

// NOK: enableHighAccuracy set to true
// Non-compliant: enableHighAccuracy set to true
const invalidOptions = { enableHighAccuracy: true, timeout: 5000 };
navigator.geolocation.getCurrentPosition(success, error, invalidOptions);

// OK: enableHighAccuracy is false by default, so its valid
// Compliant: enableHighAccuracy is false by default, so its valid
navigator.geolocation.getCurrentPosition(success);

// OK: explicit enableHighAccuracy set to false
// Compliant: explicit enableHighAccuracy set to false
const validOptions = { enableHighAccuracy: false, maximumAge: 0 };
navigator.geolocation.getCurrentPosition(success, error, validOptions);
4 changes: 2 additions & 2 deletions src/import-all-from-library.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import lodash from "lodash";
import * as _ from "underscore";
import lodash from "lodash"; // Non-compliant: lodash is entirely loaded
import * as _ from "underscore"; // Non-compliant: underscore is entirely loaded

lodash.isEmpty("");
_.isEmpty("");
27 changes: 20 additions & 7 deletions src/limit-db-query-results.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
//OK
let query = "SELECT * FROM customers LIMIT 10;";
query = "SELECT TOP 5 * FROM products;";
query = "SELECT * FROM orders FETCH FIRST 20 ROWS ONLY;";
import mysql from "mysql2";

// Compliant
let query = "SELECT * FROM customers LIMIT 10";
query = "SELECT TOP 5 * FROM products";
query = "SELECT * FROM orders FETCH FIRST 20 ROWS ONLY";
query =
"WITH numbered_customers AS (SELECT *, ROW_NUMBER() OVER (ORDER BY customer_id) AS row_num FROM customers) SELECT * FROM numbered_customers WHERE row_num <= 50;";
"WITH numbered_customers AS (SELECT *, ROW_NUMBER() OVER (ORDER BY customer_id) AS row_num FROM customers) SELECT * FROM numbered_customers WHERE row_num <= 50";

// Non-compliant
query = "SELECT id FROM bikes";

//NOK
query = "SELECT id FROM bikes;";
// Sample to execute the query
const connection = mysql.createConnection({
host: "localhost",
user: "root",

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "root" is used as [user name](1).
database: "test",
});
connection.query(query, function (_, results, fields) {
console.log(results);
console.log(fields);
});
2 changes: 1 addition & 1 deletion src/modular-import-from-library.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import isEmpty from "lodash/isEmpty";
import isEmpty from "lodash/isEmpty"; // Compliant

isEmpty("");
16 changes: 16 additions & 0 deletions src/no-css-animations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react";

function AnimatedComponent() {
return (
<div>
{/* Compliant */}
<div style={{ border: "5px solid red" }}></div>
<div class="my-awesome-element"></div>

{/* Non-compliant */}
<div style={{ animation: "background 0.3s ease" }}></div>
</div>
);
}

export default AnimatedComponent;
4 changes: 2 additions & 2 deletions src/no-empty-image-src-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React from "react";
function ImageComponent() {
return (
<div>
{/* OK */}
{/* Compliant */}
<img src="logo.svg" alt="This is a SVG image" />

{/* NOK */}
{/* Non-compliant */}
<img alt="This is an empty image" />
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/no-multiple-access-dom-element.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// NOK: same dom element accessed multiple times
// Non-compliant: same dom element accessed multiple times
function invalidShowCard() {
document.querySelector("#card").style.backgroundColor = "red";
document.querySelector("#card").innerHTML = "Hello world!";
}

// OK: dom element is stored in a variable
// Compliant: dom element is stored in a variable
function validShowCard() {
const card = document.querySelector("#card");
card.style.backgroundColor = "red";
Expand Down