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 support for Twig and Nunjucks #8

Merged
merged 4 commits into from
Aug 19, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ObsoHTML, the Obsolete HTML Checker

ObsoHTML is a Node.js script designed to scan HTML, PHP, JavaScript, and TypeScript files for obsolete or proprietary HTML attributes and elements (in scripts, it would catch JSX syntax). It helps you identify and update deprecated HTML code to be more sure to use web standards.
ObsoHTML is a Node.js script designed to scan HTML, PHP, Nunjucks, Twig, JavaScript, and TypeScript files for obsolete or proprietary HTML attributes and elements (in scripts, it would catch JSX syntax). It helps you identify and update deprecated HTML code to be more sure to use web standards.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion bin/obsohtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function walkDirectory(directory, verbose) {
if (file !== 'node_modules') {
walkDirectory(fullPath, verbose);
}
} else if (fullPath.endsWith('.html') || fullPath.endsWith('.htm') || fullPath.endsWith('.php') || fullPath.endsWith('.js') || fullPath.endsWith('.ts')) {
} else if (fullPath.endsWith('.html') || fullPath.endsWith('.htm') || fullPath.endsWith('.php') || fullPath.endsWith('.njk') || fullPath.endsWith('.twig') || fullPath.endsWith('.js') || fullPath.endsWith('.ts')) {
findObsolete(fullPath);
}
} catch (err) {
Expand Down
9 changes: 9 additions & 0 deletions bin/obsohtml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('ObsoHTML', () => {
const tempFile = path.join(tempDir, 'test.html');
const tempFileWithAttributes = path.join(tempDir, 'test_with_attributes.html');
const tempFileWithMinimizedAttributes = path.join(tempDir, 'test_with_minimized_attributes.html');
const tempTwigFile = path.join(tempDir, 'test.twig');

beforeAll(() => {
// Create a temporary directory and files
Expand All @@ -16,13 +17,15 @@ describe('ObsoHTML', () => {
fs.writeFileSync(tempFile, '<!DOCTYPE html><html><title>Test</title><body><center>Test</center></body></html>');
fs.writeFileSync(tempFileWithAttributes, '<!DOCTYPE html><html><title>Test</title><body><img src=test.jpg alt=Test align=left></body></html>');
fs.writeFileSync(tempFileWithMinimizedAttributes, '<!DOCTYPE html><html><title>Test</title><hr noshade><!-- this is not a <table> with a nowrap attribute -->');
fs.writeFileSync(tempTwigFile, '<!DOCTYPE html><html><title>Test</title><isindex>');
});

afterAll(() => {
// Clean up the temporary directory and files
fs.unlinkSync(tempFile);
fs.unlinkSync(tempFileWithAttributes);
fs.unlinkSync(tempFileWithMinimizedAttributes);
fs.unlinkSync(tempTwigFile);
fs.rmdirSync(tempDir);
});

Expand Down Expand Up @@ -53,5 +56,11 @@ describe('ObsoHTML', () => {
test('Detect obsolete minimized attributes', () => {
const result = spawnSync('node', ['bin/obsohtml.js', '-f', tempDir], { encoding: 'utf-8' });
expect(result.stdout).toContain("Found obsolete attribute 'noshade'");
expect(result.stdout).not.toContain("Found obsolete attribute 'nowrap'");
});

test('Detect obsolete elements in Twig file', () => {
const result = spawnSync('node', ['bin/obsohtml.js', '-f', tempDir], { encoding: 'utf-8' });
expect(result.stdout).toContain("Found obsolete element 'isindex'");
});
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@j9t/obsohtml",
"description": "Find obsolete HTML elements and attributes",
"author": "Jens Oliver Meiert",
"version": "1.5.0",
"version": "1.6.0",
"license": "CC-BY-SA-4.0",
"repository": {
"type": "git",
Expand Down
Loading