Skip to content

Commit

Permalink
Merge pull request #8 from j9t/feat/7
Browse files Browse the repository at this point in the history
Add support for Twig and Nunjucks
  • Loading branch information
j9t authored Aug 19, 2024
2 parents b2e42ee + 511121b commit d8574de
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
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

0 comments on commit d8574de

Please sign in to comment.