Skip to content

Commit

Permalink
Fixed path in detectFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
sebryu committed Sep 25, 2023
1 parent d7b0c73 commit 99e431e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions .github/actions/javascript/authorChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const { parse } = __nccwpck_require__(639);
const traverse = __nccwpck_require__(5008).default;
const _ = __nccwpck_require__(2947);
const fs = __nccwpck_require__(5747);
const CONST = __nccwpck_require__(4097);

const items = [
"I verified that similar component doesn't exist in the codebase",
Expand Down Expand Up @@ -243,14 +244,14 @@ function detectReactComponent(code) {
return isReactComponent;
};

function absolutePath(filename) {
return `${process.cwd()}/${filename}`;
function relativePath(filename) {
return filename.replace(`${CONST.APP_NAME}/`, '');
}

function detectFunction(changedFiles) {
console.log('detectFunction', process.cwd());
const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx'));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fs.readFileSync(absolutePath(filename), 'utf-8')));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fs.readFileSync(relativePath(filename), 'utf-8')));
}

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { parse } = require('@babel/parser');
const traverse = require('@babel/traverse').default;
const _ = require('underscore');
const fs = require('fs');
const CONST = require('../../../libs/CONST');

const items = [
"I verified that similar component doesn't exist in the codebase",
Expand Down Expand Up @@ -43,14 +44,14 @@ function detectReactComponent(code) {
return isReactComponent;
};

function absolutePath(filename) {
return `${process.cwd()}/${filename}`;
function relativePath(filename) {
return filename.replace(`${CONST.APP_NAME}/`, '');
}

function detectFunction(changedFiles) {
console.log('detectFunction', process.cwd());
const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx'));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fs.readFileSync(absolutePath(filename), 'utf-8')));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fs.readFileSync(relativePath(filename), 'utf-8')));
}

module.exports = {
Expand Down

0 comments on commit 99e431e

Please sign in to comment.