Skip to content

Commit

Permalink
fix: dotted path, tests, proper parser for hcl
Browse files Browse the repository at this point in the history
  • Loading branch information
bodinsamuel committed Jun 28, 2023
1 parent 29b732c commit 8be13a6
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 30 deletions.
25 changes: 12 additions & 13 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 @@ -38,11 +38,11 @@
},
"dependencies": {
"@actions/core": "1.10.0",
"@cdktf/hcl2json": "0.17.0",
"@octokit/plugin-retry": "^4.1.3",
"commander": "10.0.1",
"dotenv": "16.0.3",
"figures": "5.0.0",
"hcl2-parser": "1.0.3",
"kleur": "4.1.5",
"nanoid": "4.0.2",
"octokit": "2.0.14",
Expand Down
32 changes: 21 additions & 11 deletions src/provider/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,36 @@ export interface BaseProvider {

export const IGNORED_DIVE_PATHS = [
'node_modules',
'.git',
'.vscode',
'dist',
'build',
'bin',
'static',
'public',
'vendor',
'.svn',
'terraform.tfstate.d',
'migrations',
'tests',
'__fixtures__',
'__snapshots__',
'tmp',

// -- Dot folder
'.artifacts',
'.azure-pipelines',
'.dynamodb',
'.fusebox',
'.git',
// needed to detect github actions
// '.github',
'.gitlab',
'.log',
'.npm',
'.nuxt',
'.react-email',
'.serverless',
'.fusebox',
'.dynamodb',
'.vuepress',
'migrations',
'.vercel',
'.svn',
'.terraform',
'terraform.tfstate.d',
'__fixtures__',
'__snapshots__',
'.vercel',
'.vscode',
'.vuepress',
];
5 changes: 3 additions & 2 deletions src/provider/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export class FakeProvider implements BaseProvider {
const files = this.paths[pathRelative].sort();
return Promise.resolve(
files.map((file) => {
const isDir = file.endsWith('/');
return {
name: file,
type: file.endsWith('/') ? 'dir' : 'file',
name: isDir ? file.substring(0, file.length - 1) : file,
type: isDir ? 'dir' : 'file',
fp: path.join(pathRelative, file),
};
})
Expand Down
18 changes: 17 additions & 1 deletion src/rules/ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (const item of rawList) {
paths.push('example' in item.ref ? item.ref.example : item.ref.files[0]);
}

describe('npm', () => {
describe('ci', () => {
it('should match everything', async () => {
const res = await analyser({
provider: new FakeProvider({
Expand All @@ -44,4 +44,20 @@ describe('npm', () => {
'travisci',
]);
});

it.only('enforce that we match .github', async () => {
const res = await analyser({
provider: new FakeProvider({
paths: {
'/': ['.github/'],
'/.github': ['workflows/'],
'/.github/workflows': ['main.yml'],
},
files: {
'/.github/workflows/main.yml': '',
},
}),
});
expect(res.toJson('').techs).toStrictEqual(['github', 'githubactions']);
});
});
1 change: 1 addition & 0 deletions src/rules/spec/nodejs/dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('npm', () => {
'express',
'fastify',
'gcp',
'github',
'hotjar',
'influxdb',
'koa',
Expand Down
5 changes: 3 additions & 2 deletions src/rules/spec/terraform/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';

import * as hcl_parser from 'hcl2-parser';
import { parse } from '@cdktf/hcl2json';

import { listIndexed } from '../../../common/techs.js';
import { Payload } from '../../../payload/index.js';
Expand All @@ -25,8 +25,9 @@ export const detectTerraformComponent: ComponentMatcher = async (

let json: Record<string, any>;
try {
json = hcl_parser.parseToObject(content)[0];
json = await parse(file.fp, content);
} catch (err) /* istanbul ignore next */ {
console.warn('Failed to parse HCL', err);
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/rules/tool/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ register({
tech: 'github',
files: ['.github'],
dependencies: [
{ type: 'npm', name: 'octokit' },
{ type: 'npm', name: /^@octokit\//, example: '@octokit/types' },
{ type: 'terraform', name: 'registry.terraform.io/integrations/github' },
],
});

0 comments on commit 8be13a6

Please sign in to comment.