Skip to content
Open
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
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

55 changes: 0 additions & 55 deletions .eslintrc.json

This file was deleted.

15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Lint Filenames action

<p align="center">
<a href="https://github.com/batista/lint-filenames/actions?query=workflow%3Abuild-test"><img alt="build-test action status" src="https://github.com/batista/lint-filenames/workflows/build-test/badge.svg"></a>
<a href="https://github.com/batista/lint-filenames/actions?query=workflow%3ACodeQL"><img alt="code-ql status" src="https://github.com/batista/lint-filenames/workflows/CodeQL/badge.svg"></a>
<a href="https://github.com/batista/lint-filenames/blob/main/LICENSE"><img alt="license MIT" src="https://img.shields.io/github/license/batista/lint-filenames"></a>
<a href="https://github.com/scheduleonce/lint-filenames/actions?query=workflow%3Abuild-test"><img alt="build-test action status" src="https://github.com/scheduleonce/lint-filenames/workflows/build-test/badge.svg"></a>
<a href="https://github.com/scheduleonce/lint-filenames/actions?query=workflow%3ACodeQL"><img alt="code-ql status" src="https://github.com/scheduleonce/lint-filenames/workflows/CodeQL/badge.svg"></a>
<a href="https://github.com/scheduleonce/lint-filenames/blob/main/LICENSE"><img alt="license MIT" src="https://img.shields.io/github/license/scheduleonce/lint-filenames"></a>
</p>

**Lint Filenames** is an simple github action to help you ensure certain patterns
Expand All @@ -15,7 +15,7 @@ are followed in a given folder in your repository.

### `path`

**Required** The path to a directory to check the filenames.
**Required** A [glob path](https://github.com/isaacs/node-glob) to search for files.

### `pattern`

Expand All @@ -38,7 +38,7 @@ The number of files analyzed.
to ensure all files match the pattern `/^.+\..+$/` in the `my-files` directory, use the following:

```yml
uses: batista/lint-filenames@v1
uses: scheduleonce/lint-filenames@v1
name: Validating my-folder filenames
with:
path: './my-folder'
Expand Down Expand Up @@ -74,9 +74,10 @@ $ npm test
✓ 04 - Passes for no `.dotfiles`
✓ 05 - Passes for files with `a` in the name (1 ms)
✓ 06 - Passes for json files `*.json` (1 ms)
√ 07 - Passes for folders (3 ms)

Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 0.559 s, estimated 2 s
Ran all test suites.
Expand Down Expand Up @@ -111,7 +112,7 @@ with:
pattern: "\\.json$"
```

See the [actions tab](https://github.com/batista/lint-filenames/actions) for runs of this action! :rocket:
See the [actions tab](https://github.com/scheduleonce/lint-filenames/actions) for runs of this action! :rocket:

## Usage:

Expand Down
Empty file.
Empty file.
Empty file.
73 changes: 46 additions & 27 deletions __tests__/validate-filenames.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * as nodePath from 'path';
/* eslint-disable @typescript-eslint/no-floating-promises */

import * as nodePath from 'node:path';
import assert from 'node:assert/strict';
import { describe, it, beforeEach, mock } from 'node:test';

import { validateFilenames } from '../src/validate-filenames';

Expand All @@ -12,77 +16,92 @@ const TEST_CONFIGS = {
noDot: { path: '04-no-dot-files', pattern: '^[^\\.].+$' },
containsA: { path: '05-contains-a-files', pattern: 'a+' },
json: { path: '06-json-files', pattern: '\\.json$' },
includeFolders: {
path: '07-include-folders',
pattern: '^[a-z0-9]+(-[a-z0-9]+)*$',
},
};

let spy: jest.SpyInstance;

beforeEach(() => {
// We silence the console for better readability in tests
spy = jest.spyOn(console, 'log').mockImplementation();
});

afterEach(() => {
spy.mockRestore();
mock.method(console, 'log', () => {});
});

describe('Name of the group', () => {
describe('validateFilenames function', () => {
it('01 - Passes for any character files', async () => {
const testConfig = TEST_CONFIGS.anyCharacter;
const path = nodePath.join(__dirname, 'test-files', testConfig.path);
const dirPath =
nodePath.join(__dirname, 'test-files', testConfig.path) + '/*';
const pattern = new RegExp(testConfig.pattern);

const expected = { totalFilesAnalyzed: 5, failedFiles: [] };

await expect(validateFilenames(path, pattern)).resolves.toEqual(expected);
const result = await validateFilenames(dirPath, pattern);
assert.deepStrictEqual(result, expected);
});

it('02 - Passes for `name.ext` files', async () => {
const testConfig = TEST_CONFIGS.nameDotExtension;
const path = nodePath.join(__dirname, 'test-files', testConfig.path);
const dirPath =
nodePath.join(__dirname, 'test-files', testConfig.path) + '/*';
const pattern = new RegExp(testConfig.pattern);

const expected = { totalFilesAnalyzed: 1, failedFiles: [] };

await expect(validateFilenames(path, pattern)).resolves.toEqual(expected);
const result = await validateFilenames(dirPath, pattern);
assert.deepStrictEqual(result, expected);
});

it('03 - Passes for `.dotfiles`', async () => {
const testConfig = TEST_CONFIGS.dotFile;
const path = nodePath.join(__dirname, 'test-files', testConfig.path);
const dirPath =
nodePath.join(__dirname, 'test-files', testConfig.path) + '/.*';
const pattern = new RegExp(testConfig.pattern);

const expected = { totalFilesAnalyzed: 1, failedFiles: [] };

await expect(validateFilenames(path, pattern)).resolves.toEqual(expected);
const result = await validateFilenames(dirPath, pattern);
assert.deepStrictEqual(result, expected);
});

it('04 - Passes for no `.dotfiles`', async () => {
const testConfig = TEST_CONFIGS.noDot;
const path = nodePath.join(__dirname, 'test-files', testConfig.path);
const dirPath =
nodePath.join(__dirname, 'test-files', testConfig.path) + '/*';
const pattern = new RegExp(testConfig.pattern);

const expected = { totalFilesAnalyzed: 5, failedFiles: [] };

await expect(validateFilenames(path, pattern)).resolves.toEqual(expected);
const result = await validateFilenames(dirPath, pattern);
assert.deepStrictEqual(result, expected);
});

it('05 - Passes for files with `a` in the name', async () => {
const testConfig = TEST_CONFIGS.containsA;
const path = nodePath.join(__dirname, 'test-files', testConfig.path);
const dirPath =
nodePath.join(__dirname, 'test-files', testConfig.path) + '/*';
const pattern = new RegExp(testConfig.pattern);

const expected = { totalFilesAnalyzed: 5, failedFiles: [] };

await expect(validateFilenames(path, pattern)).resolves.toEqual(expected);
const result = await validateFilenames(dirPath, pattern);
assert.deepStrictEqual(result, expected);
});

it('06 - Passes for json files `*.json`', async () => {
const testConfig = TEST_CONFIGS.json;
const path = nodePath.join(__dirname, 'test-files', testConfig.path);
const dirPath =
nodePath.join(__dirname, 'test-files', testConfig.path) + '/*';
const pattern = new RegExp(testConfig.pattern);

const expected = { totalFilesAnalyzed: 5, failedFiles: [] };

await expect(validateFilenames(path, pattern)).resolves.toEqual(expected);
const result = await validateFilenames(dirPath, pattern);
assert.deepStrictEqual(result, expected);
});

it('07 - Passes for folders', async () => {
const testConfig = TEST_CONFIGS.includeFolders;
const dirPath =
nodePath.join(__dirname, 'test-files', testConfig.path) + '/**';
const pattern = new RegExp(testConfig.pattern);
const expected = { totalFilesAnalyzed: 6, failedFiles: [] };

const result = await validateFilenames(dirPath, pattern);
assert.deepStrictEqual(result, expected);
});
});
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Lint Filenames'
name: 'Lint Filenames Glob'
description: 'This github action validates if all files in a given folder match the given regex pattern.'
branding:
icon: 'folder'
Expand All @@ -16,5 +16,5 @@ outputs:
total-files-analyzed:
description: 'The number of files analyzed.'
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
Loading