-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06ac712
commit 42d9bb4
Showing
9 changed files
with
206 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
sample_project/ | ||
sample_project_2/ | ||
*.test.* | ||
*.spec.* | ||
src/ | ||
.vscode-test/ | ||
.vscode/ | ||
.github/ | ||
*.png | ||
*.gif | ||
*.vsix | ||
.eslintrc.json | ||
.vscode-test.mjs | ||
.vscodeignore | ||
extension.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<body> | ||
<!-- Following should be fine --> | ||
<h1>A title</h1> | ||
<p>Some text</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Following should be OK | ||
const finite = isFinite(1000 / x); | ||
const x = parseFloat("55.5"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
body { | ||
/* Following should be OK */ | ||
background: #ffffff; | ||
font-family: "Source Sans Pro", sans-serif; | ||
font-style: normal; | ||
font-weight: 300; | ||
} | ||
|
||
/* Following should be OK */ | ||
@font-face { | ||
font-family: "Source Sans Pro"; | ||
src: url(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env node | ||
|
||
import { program } from "commander"; | ||
import { minimatch } from "minimatch"; | ||
import { readFileSync, readdirSync } from "fs"; | ||
import path from "path"; | ||
import kleur from "kleur"; | ||
import { findIssues, CompatIssue } from "./browser-compatibility-checker"; | ||
const compatIssues: { | ||
[path: string]: { [key: string]: CompatIssue }; | ||
} = require("./browser-compatibility-checker/compat-issues.json"); | ||
|
||
interface CliOptions { | ||
folder: string; | ||
browsers: string[] | string; | ||
} | ||
|
||
program | ||
.description("Scan files for browser compatibility issues") | ||
.option("-f, --folder <folder>", "Folder to scan") | ||
.option( | ||
"-b, --browsers [browsers]", | ||
"Comma seperated list of browsers to check", | ||
[ | ||
"chrome", | ||
"edge", | ||
"firefox", | ||
"opera", | ||
"safari", | ||
"ie", | ||
"chrome_android", | ||
"firefox_android", | ||
"opera_android", | ||
"safari_ios", | ||
"samsunginternet_android", | ||
"webview_android", | ||
] | ||
); | ||
|
||
program.parse(process.argv); | ||
const { folder, browsers } = program.opts() as CliOptions; | ||
const browsersToCheck = | ||
typeof browsers === "string" ? browsers.split(",") : browsers; | ||
|
||
if (!folder) { | ||
console.error(kleur.red("No folder path provided.")); | ||
process.exit(1); | ||
} | ||
|
||
const files = readdirSync(folder, { recursive: true, encoding: "utf8" }); | ||
console.log(`Scanning: ${folder} (${files.length} files)`); | ||
let hasIssue = false; | ||
|
||
for (const [fileRegex, issues] of Object.entries(compatIssues)) { | ||
for (const file of files) { | ||
const filePath = path.join(folder, file); | ||
if (minimatch(filePath, fileRegex, { nocase: true })) { | ||
const text = readFileSync(filePath, "utf8"); | ||
const matches = findIssues(text, issues, browsersToCheck, false); | ||
if (matches.length > 0) { | ||
hasIssue = true; | ||
console.error(kleur.red(`Issues found with ${filePath}:`)); | ||
for (const { message } of matches) { | ||
console.log(` - ${message}`); | ||
} | ||
} else { | ||
console.log(kleur.green(filePath)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (hasIssue) { | ||
console.log( | ||
"Issues detected. Address these issues or change --browsers to ingore irrelavant browser issues" | ||
); | ||
process.exit(1); | ||
} else { | ||
console.log("No issues detected!"); | ||
} |