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

Verify Gifs Filename Linter #366

Merged
merged 4 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions .github/workflows/gifs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Verify Gifs Filename

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Verify Gifs Filename
run: |
npm install
npm run compile:test
npm run test:gifs
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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@
"lint:fix": "eslint src --ext ts --fix && prettier --write src",
"test": "node ./out/test/runTest.js",
"test:coverage": "COVERAGE=1 node ./out/test/runTest.js",
"test:web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js"
"test:web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js",
"test:gifs": "node ./out/test/gifs.js"
},
"devDependencies": {
"@rbarilani/remove-source-map-url-webpack-plugin": "^1.1.0",
Expand Down
72 changes: 72 additions & 0 deletions src/test/gifs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as fs from 'fs';

const pets = [
'cat',
'chicken',
'clippy',
'cockatiel',
'crab',
'dog',
'fox',
'mod',
'rocky',
'rubber-duck',
'snake',
'totoro',
'zappy',
];

const colors = [
'red',
'white',
'purple',
'gray',
'yellow',
'green',
'black',
'brown',
'lightbrown',
];
const states = [
'idle',
'run',
'swipe',
'land',
'walk',
'walk_fast',
'wallclimb',
'wallgrab',
'with_ball',
'fall_from_grab',
'jump',
'lie',
];

const fps = ['8fps'];

const gifFilenamePattern = new RegExp(
`^(${colors.join('|')})_(${states.join('|')})_(${fps.join('|')}).gif$`,
);

function checkGifFilenames(folder: string) {
const filenames = fs.readdirSync(folder);
filenames.forEach((filename) => {
if (pets.includes(filename)) {
const petFolder = `${folder}/${filename}`;
const petFilenames = fs.readdirSync(petFolder);
petFilenames.forEach((petFilename) => {
if (
petFilename.endsWith('.gif') &&
!gifFilenamePattern.test(petFilename)
) {
console.error(
`Filename "${petFilename}" does not match pattern in folder ${petFolder}. The pattern should be petColor_petState_8fps.gif.`,
);
}
});
}
});
}

const mediaFolder = './media';
checkGifFilenames(mediaFolder);