150 examples

Logic error

Logical mistake resulting in incorrect outcomes.

[ FAQ1 ]

what is a logic error?

A logic error is a mistake in the way a program's code is structured or implemented, causing it to behave incorrectly, produce wrong outputs, or fail to meet intended requirements—even though it compiles or executes without syntax errors. Unlike syntax errors, logic errors don't prevent the program from running; instead, they lead to unexpected behaviors, incorrect results, or application crashes under specific conditions. Common examples include incorrect conditional statements, flawed control-flow logic, off-by-one errors in loops, or miscalculations in arithmetic operations.
[ FAQ2 ]

How to fix logic errors in code

To fix logic errors, carefully review your code logic and clearly define the expected behaviors and outcomes. Use debugging tools in languages like Python or Java to step through code execution line-by-line, identifying precisely where logic deviates from expectations. Write comprehensive unit tests that reflect desired behavior, helping catch logic errors early. Add detailed logging or print statements strategically throughout code execution to trace variable states and control flow. Regular code reviews, systematic debugging, and structured problem-solving approaches significantly reduce logic errors and improve overall code correctness.
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: using `if (prettier.check(input, options))` now flags correctly formatted files. It should be negated to warn for unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted, so this will warn about properly formatted files instead of unformatted ones
suggested fix
+ if (!prettier.check(input, options)) {
diff block
const handleCarrierChange = async (carrierId: string) => {
const carrier = carriers.get(carrierId);
- const shouldShowDatePicker = carrier === undefined ? true : !(await carrier.ableToTrackRemotely());
+ const shouldShowDatePicker = carrier === undefined ? true : !carrier.ableToTrackRemotely();
setShowDatePicker(shouldShowDatePicker);
};
Greptile
greptile
logic: Missing await on carrier.ableToTrackRemotely() returns a Promise instead of a boolean, causing logic errors in showing the date picker. Please revert to using 'await carrier.ableToTrackRemotely()'.
suggested fix
+ const handleCarrierChange = async (carrierId: string) => {
+ const carrier = carriers.get(carrierId);
+ const shouldShowDatePicker = carrier === undefined ? true : !(await carrier.ableToTrackRemotely());
+ setShowDatePicker(shouldShowDatePicker);
+ };
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is already formatted correctly, so this warning triggers for properly formatted files
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. `prettier.check()` returns true when code is already formatted correctly, so this will warn about correctly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: The condition should trigger when prettier.check(input, options) returns false, not true.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when code is already formatted correctly, so this condition is inverted from the original. This will warn about properly formatted files instead of improperly formatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. `prettier.check` returns true when formatting is correct, so this will warn about correctly formatted files instead of incorrectly formatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: the check condition is reversed. Should use if (!prettier.check(...)) to report misformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: the condition was inverted. It should flag files that fail check (!prettier.check(input, options)).
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition reversed. Should warn when prettier.check(input, options) returns false.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when code is already formatted correctly, so this condition is inverted and will warn about properly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
You're right, there's a logic error in the code. The `prettier.check()` function returns `true` when the code is already formatted correctly, so the current condition is inverted. It's currently warning about properly formatted files instead of unformatted ones. Here's the fix:
suggested fix
+ if (!prettier.check(input, options)) {
This will correctly warn about files that need formatting (when `prettier.check()` returns `false`), which is the intended behavior of the script.
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: check condition reversed. It should log files that fail prettier.check, not those that pass.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: prettier.check returns true for formatted files. Invert condition (if (!prettier.check(...))) to warn for misformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
return data;
}
- // UPDATES
- static async update({
+ static async getEntitlementsByProductId({
sb,
productId,
orgId,
env,
- update,
}: {
sb: SupabaseClient;
productId: string;
orgId: string;
env: AppEnv;
+ }) {
+ const { data, error } = await sb
+ .from("entitlements")
+ .select("*, feature:features(id, name, type)")
+ .eq("product_id", productId)
+ .eq("org_id", orgId)
+ .eq("env", env);
+
+ if (error) {
+ if (error.code !== "PGRST116") {
+ return [];
+ }
Greptile
greptile
logic: Logic error in error handling - if error.code !== 'PGRST116' returns empty array, but should throw error instead. Current code returns empty array for all errors except PGRST116.
suggested fix
+ if (error.code === "PGRST116") {
return [];
}
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when code is already formatted correctly, so this condition is inverted. Should be `if (!prettier.check(input, options))`.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when formatting is correct, so this condition is inverted. Warning will show for correctly formatted files and skip files with issues.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. prettier.check returns true when code is already formatted correctly, so this will warn about files that don't need formatting.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
You're right, there's a logic error in the condition. The `prettier.check()` function returns `true` when the code is already formatted correctly, so the current condition is inverted. When it returns `true` (meaning the file is already formatted), the code is showing a warning, which is the opposite of what we want. Here's the fix:
suggested fix
+ if (!prettier.check(input, options)) {
This way, the warning will only show for files that need formatting (when `prettier.check()` returns `false`).
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: condition reversed. Should warn when prettier.check returns false.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() condition reversed; should warn on false result.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when code is already formatted correctly. This inverts the intended behavior - warnings will show for correctly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when code is already formatted correctly, so this condition is inverted from the original intent.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
You're right, there's a logic error in the code. The `prettier.check()` function returns `true` when the code is already formatted correctly, so the current condition is inverted from what we want. The fix is to negate the condition so it correctly identifies files that need formatting:
suggested fix
+ if (!prettier.check(input, options)) {
This change will make the code work as intended - it will only show warnings for files that need formatting (when `prettier.check()` returns `false`).
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when file IS formatted correctly, so this condition is backwards and will warn about properly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when code is already formatted correctly. This inverts the intended behavior - now showing warnings for correctly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
You're right, there's a logic error in the code. The `prettier.check()` function returns `true` when the code is already formatted correctly, but the current condition is showing warnings for correctly formatted files instead of files that need formatting. Here's the fix:
suggested fix
+ if (!prettier.check(input, options)) {
This change will correctly show warnings only for files that need formatting (when `prettier.check()` returns `false`), which aligns with the original intent of the code.
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is already formatted correctly, so this condition is backwards
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: 'if (prettier.check(input, options))' is inverted. Should warn if check fails.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. `prettier.check` returns true when code is formatted correctly, so this will warn about properly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
+import type { Command } from "@commander-js/extra-typings";
+import console from "node:console";
+import process from "node:process";
+import { Shescape } from "shescape";
+import { execvp } from "@alphahydrae/exec";
+import {
+ logAndQuit,
+ logSessionTokenExpiredAndQuit,
+} from "../helpers/errors.ts";
+import { getApiUrl } from "../helpers/urls.ts";
+import { getAuthToken } from "../helpers/config.ts";
+
+type SshHostKey = {
+ keyType: string;
+ base64EncodedKey: string;
+};
+
+export function registerSsh(program: Command) {
+ program
+ .command("ssh")
+ .option("-q, --quiet", "Quiet mode", false)
+ .argument("<vm_id>", "The VM's id", parseInt)
+ .allowExcessArguments(false)
+ .action(async (vm_id, options) => {
+ let sshHostname: string;
+ let sshUsername: string | undefined;
+ let sshPort: number | undefined;
+ let sshHostKeys: SshHostKey[];
+
+ const response = await fetch(await getApiUrl("vms_ssh_get"), {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${await getAuthToken()}`,
+ },
+ body: JSON.stringify({ vm_id: vm_id.toString() }),
+ });
+
+ if (!response.ok) {
+ if (response.status === 401) {
+ logSessionTokenExpiredAndQuit();
+ }
+
+ logAndQuit(
+ `Failed to retrieve ssh information: ${response.statusText}`
+ );
+ }
+
+ const data = (await response.json()) as {
+ ssh_hostname: string;
+ ssh_port: number;
+ ssh_host_keys: SshHostKey[] | undefined;
+ };
+ sshHostname = data.ssh_hostname;
+ sshPort = data.ssh_port;
+ sshHostKeys = data.ssh_host_keys || [];
+ logAndQuit(`Unknown vm index: ${vm_id}`);
Greptile
greptile
logic: Critical logic error: logAndQuit is always invoked, blocking execution. Likely unintended.
suggested fix
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. prettier.check returns true when code is formatted correctly, so this will warn about correctly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when formatting is correct, so this condition is inverted from the original. This will warn about correctly formatted files instead of incorrectly formatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: expected condition was 'if (!prettier.check(input, options))' to report unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition is inverted. Should warn on files that _fail_ the prettier.check.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: 'if (prettier.check(input, options))' is reversed. Should check for a failure (e.g. '!prettier.check(input, options)') to warn on improperly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when the file is already formatted correctly. This inverts the intended behavior - now showing warnings for correctly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true for correctly formatted files, false for malformatted ones. This inverted condition will warn about properly formatted files
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: condition reversed. Should use '!prettier.check(input, options)' to report non-compliant files.
suggested fix
+ } else {
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
+import { canActivateRepeatedly, hasActions, hasEvents } from './surveys-utils'
+import { Survey } from '../../../posthog-core/src/posthog-surveys-types'
+
+export function getActiveMatchingSurveys(
+ surveys: Survey[],
+ flags: Record<string, string | boolean>,
+ seenSurveys: string[],
+ activatedSurveys: ReadonlySet<string>,
+ lastSeenSurveyDate: Date | undefined
+): Survey[] {
+ return surveys.filter((survey) => {
+ // Is Active
+ if (!survey.start_date || survey.end_date) {
Greptile
greptile
logic: Logic error: returns false when start_date exists, which is the opposite of what's intended. Should be `if (!survey.start_date) return false`
suggested fix
if (!survey.start_date || survey.end_date) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: 'if (prettier.check(input, options))' should likely be 'if (!prettier.check(input, options))' to warn when formatting fails.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when code is already formatted correctly, so this condition is inverted from the original. This will show warnings for correctly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
+use arrow::array::{BooleanArray, Int64Array, RecordBatch, StringArray};
+use chrono::Utc;
+use config::{
+ get_config,
+ meta::stream::{FileKey, FileListDeleted, StreamType},
+};
+use hashbrown::HashMap;
+use infra::{
+ errors,
+ file_list::{FileRecord, calculate_max_ts_upper_bound},
+};
+
+use super::search::datafusion::exec::prepare_datafusion_context;
+use crate::service::search::datafusion::exec::create_parquet_table;
+
+const HOUR_IN_MILI: i64 = 3600 * 1000;
+
+#[inline]
+fn round_down_to_hour(v: i64) -> i64 {
+ v - (v % HOUR_IN_MILI * 1000)
+}
Greptile
greptile
logic: Potential logic error: In 'round_down_to_hour', the expression 'v - (v % HOUR_IN_MILI * 1000)' multiplies the remainder by 1000. If v is already in milliseconds and HOUR_IN_MILI represents 1 hour in milliseconds, this will subtract an overly large amount. Possibly intended to use 'v - (v % HOUR_IN_MILI)'.
suggested fix
#[inline]
fn round_down_to_hour(v: i64) -> i64 {
+ v - (v % HOUR_IN_MILI)
}
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error in prettier.check() condition - this will now warn when files are properly formatted instead of when they need formatting
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error in prettier.check() condition - it returns true when the code is already formatted correctly, so this warning will trigger for properly formatted files instead of unformatted ones
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. `prettier.check()` returns true when code is already formatted correctly, so this will warn about files that don't need formatting.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition is reversed. Should check if !prettier.check(input, options) to warn about incorrectly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when the file is already formatted correctly. This condition is inverted and will warn about properly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when code is already formatted correctly, so this condition is inverted. Should be `if (!prettier.check(input, options))`.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when code is already formatted correctly, so this condition is inverted from the original. This will warn about correctly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition inverted. Should flag files that fail prettier.check().
suggested fix
+ } else {
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. prettier.check returns true when the file is already formatted correctly, so this will warn about correctly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition is inverted. Expected 'if (!prettier.check(input, options)) { ... }', but it's 'if (prettier.check(input, options)) { ... }'.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition is inverted. prettier.check returns true if file is formatted correctly, so warning block is triggered incorrectly.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted. This condition is inverted and will warn for properly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: Prettier.check condition is inverted. It should warn when check returns false.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: The condition is inverted. Use '!prettier.check(input, options)' to warn on unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition inverted. It should warn when prettier.check(input, options) returns false.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: the condition 'if (prettier.check(input, options))' should likely be inverted to warn when files do not pass the check.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
+import { showToast, Toast } from "@raycast/api";
+import { createTimeEntry, stopTimeEntry, Me, togglProject } from "@/api";
+import { Task, Project } from "@doist/todoist-api-typescript";
+import { TodoistApi } from "@doist/todoist-api-typescript";
+import { todoistApiToken } from "@/helpers/preferences";
+
+const todoistApi = new TodoistApi(todoistApiToken);
+export async function startTogglTimer(
+ task: Task,
+ todoistProjects: Project[] | undefined,
+ togglMe: Me,
+ togglProjects: togglProject[],
+ refreshTimer: () => void,
+) {
+ const currentTodoistProject = todoistProjects?.find((project) => project.id === task.projectId);
+ const togglProjectId = currentTodoistProject?.name.indexOf("@")
+ ? currentTodoistProject?.name.slice(currentTodoistProject?.name.indexOf("@") + 1)
+ : null;
Greptile
greptile
logic: Logic error in project ID parsing - indexOf('@') returns -1 if not found, which evaluates to truthy. This will incorrectly parse project IDs when @ is not present
suggested fix
+ const togglProjectId = currentTodoistProject?.name.includes("@")
? currentTodoistProject?.name.slice(currentTodoistProject?.name.indexOf("@") + 1)
: null;
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: prettier.check is used without negation. Should check if (!prettier.check(...)) to flag misformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: the check condition is inverted. prettier.check returns true when file is properly formatted; likely should log when check returns false.
suggested fix
+ } else {
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: 'prettier.check' condition is inverted. It should be 'if (!prettier.check(input, options))' to warn on unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: inverted condition. 'prettier.check' now triggers a warning when returning true. This likely reverses the intended behavior.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition reversed. Expected: if (!prettier.check(input, options)).
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: 'prettier.check' condition is reversed. Should warn only if check fails (i.e., use '!prettier.check(input, options)').
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: 'prettier.check' condition was inverted. It should warn when check returns false.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: the condition for prettier.check is inverted. It now logs files that are already formatted.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log
diff block
const handleSave = () => {
// Execute the save function here
if (isAnalyticsEnabled !== undefined) {
- window.electronStore.setAnalyticsMode(isAnalyticsEnabled)
- setUserHasMadeUpdate(false)
+ window.electronStore.setAnalyticsMode(!isAnalyticsEnabled)
+ setIsAnalyticsEnabled(!isAnalyticsEnabled)
+ posthog.capture('analytics_disabled')
}
Greptile
greptile
logic: Logic error: posthog.capture('analytics_disabled') is called when toggling in either direction, not just when disabling analytics
suggested fix
window.electronStore.setAnalyticsMode(!isAnalyticsEnabled)
setIsAnalyticsEnabled(!isAnalyticsEnabled)
+ posthog.capture(isAnalyticsEnabled ? 'analytics_disabled' : 'analytics_enabled')
+ }
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition reversed. Should warn on !prettier.check(input, options) rather than prettier.check(input, options).
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: the check condition is inverted. It now logs correctly formatted files instead of ones failing the check.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: using 'if (prettier.check(input, options))' now triggers a warning when files are formatted correctly; should likely be 'if (!prettier.check(input, options))'.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when file is already formatted, false when it needs formatting. This condition is backwards.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: 'if (prettier.check(input, options))' should likely be negated to check for misformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition reversed. Should warn if file is not formatted (use '!prettier.check(input, options)')
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: 'prettier.check' returns true when formatted. Warning should trigger when check returns false.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: condition inverted. Use '!prettier.check(input, options)' to flag unformatted files.
suggested fix
+ } else {
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: the check condition is inverted. Should warn for !prettier.check(input, options) instead of prettier.check(input, options).
suggested fix
+ } else {
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition inverted. Should warn when prettier.check(input, options) returns false.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: using 'if (prettier.check(input, options))' flags files that pass the check. Should be inverted.
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: Changed condition on line 45 is reversed. Should trigger warning if !prettier.check(input, options).
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: 'prettier.check' condition seems inverted; likely should be '!prettier.check(input, options)' to correctly identify files needing formatting.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: Condition inverted. It now warns when prettier.check returns true, meaning the file is already formatted.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
type SetAudioDeviceActionProps = {
device: AudioDevice;
type: "input" | "output";
+ current?: AudioDevice;
};
-function SetAudioDeviceAction({ device, type }: SetAudioDeviceActionProps) {
+function SetAudioDeviceAction({ device, type, current }: SetAudioDeviceActionProps) {
return (
<Action
title={`Set as ${type === "input" ? "Input" : "Output"} Device`}
icon={{ source: type === "input" ? "mic.png" : "speaker.png", tintColor: Color.PrimaryText }}
onAction={async () => {
try {
- await (type === "input" ? setDefaultInputDevice(device.id) : setOutputAndSystemDevice(device.id));
+ await (type === "input" ? setDefaultInputDevice(device.id) : setOutputAndSystemDevice(device, current));
closeMainWindow({ clearRootSearch: true });
popToRoot({ clearSearchBar: true });
showHUD(`Set "${device.name}" as ${type} device`);
- } catch (e) {
- console.log(e);
+ } catch {
showToast(Toast.Style.Failure, `Failed setting "${device.name}" as ${type} device`);
}
}}
/>
);
}
-async function setOutputAndSystemDevice(deviceId: string) {
+async function setOutputAndSystemDevice(device: AudioDevice, current?: AudioDevice) {
const { systemOutput } = getPreferenceValues();
- await setDefaultOutputDevice(deviceId);
+ await setDefaultOutputDevice(device.id);
+ if (!current) {
+ await LocalStorage.setItem("lastUsedDevice", JSON.stringify(current));
+ }
Greptile
greptile
logic: Logic error: storing 'current' in LocalStorage when current is undefined. This condition should be reversed to store the device when current IS defined.
suggested fix
+ if (current) {
await LocalStorage.setItem("lastUsedDevice", JSON.stringify(current));
}
diff block
function evalToString(ast /* : Object */) /* : string */ {
switch (ast.type) {
case 'StringLiteral':
+ return ast.value + ''; // Unnecessary string conversion
case 'Literal': // ESLint
- return ast.value;
+ return ast.value || ''; // Silent failure for null/undefined values
case 'BinaryExpression': // `+`
- if (ast.operator !== '+') {
- throw new Error('Unsupported binary operator ' + ast.operator);
- }
+ // Missing operator check, allowing all operators
return evalToString(ast.left) + evalToString(ast.right);
Greptile
greptile
logic: Missing operator check; allows all binary operators. Could introduce logic errors.
suggested fix
+ // Only allow + operator for string concatenation
+ if (ast.operator !== '+') return '';
+ return evalToString(ast.left) + evalToString(ast.right);
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: 'if (prettier.check(input, options))' likely needs inversion to warn only if files are not formatted correctly.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: The condition on line 45 now warns when prettier.check returns true (i.e. file is formatted) instead of when it is false.
suggested fix
+ } else {
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition inverted. Should be 'if (!prettier.check(input, options))' for reporting unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: prettier.check() returns true if file is formatted; condition should be inverted to warn on misformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: prettier.check condition is inverted; should warn on false, not true.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition reversed. It now warns if prettier.check returns true (i.e. file is formatted). It should check for false.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: prettier.check returns true when the file is formatted. This condition should be inverted to warn for unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: 'prettier.check(input, options)' is reversed. It should warn when the file is not properly formatted.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: condition reversed. Expected '!prettier.check(...)' to flag unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition for prettier.check() is inverted. Previously, a failing check triggered warnings; now files passing check trigger the warning.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true if the file is properly formatted. Likely should be if (!prettier.check(input, options)) instead.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: the condition is inverted. File warnings should trigger when !prettier.check(input, options).
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: used 'if (prettier.check(...))' instead of checking for failures. Likely needs to be '!prettier.check(...)'.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: check condition is inverted. Expected to warn if prettier.check returns false.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition inverted. Prettier.check() returns true for correctly formatted files. Should use '!prettier.check(input, options)' here.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition should be !prettier.check(input, options) to warn on formatting issues.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: using 'if (prettier.check(input, options))' warns for correctly formatted files. Should be 'if (!prettier.check(input, options))'.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
+import { ActivityList } from '@/activities/components/ActivityList';
+import { ActivityRow } from '@/activities/components/ActivityRow';
+import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
+import { SMSText, TwilioMessage } from '@/activities/types/SMSText';
+import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';
+import { Person } from '@/people/types/Person';
+import styled from '@emotion/styled';
+import axios from 'axios';
+import { useEffect, useRef, useState } from 'react';
+import { H1Title, H1TitleFontColor, Section } from 'twenty-ui';
+import { formatToHumanReadableDate } from '~/utils/date-utils';
+
+// Styled components copied from EmailThread
+const StyledContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${({ theme }) => theme.spacing(6)};
+ padding: ${({ theme }) => theme.spacing(6, 6, 2)};
+ height: 100%;
+ overflow: auto;
+`;
+
+const StyledScrollableContainer = styled.div`
+ max-height: 70vh;
+ overflow: auto;
+`;
+const StyledH1Title = styled(H1Title)`
+ display: flex;
+ gap: ${({ theme }) => theme.spacing(2)};
+`;
+const StyledTextCount = styled.span`
+ color: ${({ theme }) => theme.font.color.light};
+`;
+const StyledSenderNames = styled.span`
+ display: flex;
+ margin: ${({ theme }) => theme.spacing(0, 1)};
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+`;
+const StyledBody = styled.span`
+ color: ${({ theme }) => theme.font.color.tertiary};
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+`;
+const StyledReceivedAt = styled.div`
+ font-size: ${({ theme }) => theme.font.size.sm};
+ font-weight: ${({ theme }) => theme.font.weight.regular};
+ padding: ${({ theme }) => theme.spacing(0, 1)};
+ margin-left: auto;
+`;
+
+export const SMSTexts = ({
+ targetableObject,
+}: {
+ targetableObject: ActivityTargetableObject;
+}) => {
+ const [textData, setTextData] = useState<any[]>([]);
+
+ const { record: person, loading } = useFindOneRecord<Person>({
+ objectNameSingular: targetableObject.targetObjectNameSingular,
+ objectRecordId: targetableObject.id,
+ recordGqlFields: {
+ phones: true,
+ },
+ });
+
+ const scrollRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
+ async function fetchTexts() {
+ if (!person || loading) return;
+
+ const apiUrl = process.env.REACT_APP_TWILIO_API_URL;
+ const accountSid = process.env.REACT_APP_TWILIO_ACCOUNT_SID as string;
+ const authToken = process.env.REACT_APP_TWILIO_AUTH_TOKEN as string;
+ const personPhoneNumber = `${person.phones.primaryPhoneCallingCode}${person.phones.primaryPhoneNumber}`;
+
+ try {
+ const [toResponse, fromResponse] = await Promise.all([
+ await axios.get(
+ `${apiUrl}/2010-04-01/Accounts/${accountSid}/Messages.json?To=${personPhoneNumber}`,
+ {
+ auth: {
+ username: accountSid,
+ password: authToken,
+ },
+ },
+ ),
+ await axios.get(
+ `${apiUrl}/2010-04-01/Accounts/${accountSid}/Messages.json?From=${personPhoneNumber}`,
+ {
+ auth: {
+ username: accountSid,
+ password: authToken,
+ },
+ },
+ ),
+ ]);
+
+ const texts = [
+ ...toResponse.data.messages,
+ ...fromResponse.data.messages,
+ ];
+ const textsSortedByDateDescending = texts.sort(
+ (a, b) =>
+ new Date(a.date_sent).valueOf() - new Date(b.date_sent).valueOf(),
+ );
Greptile
greptile
logic: Sorting logic error. New Date(a.date_sent) - New Date(b.date_sent) sorts ascending. To get descending order, reverse subtraction.
suggested fix
const textsSortedByDateDescending = texts.sort(
(a, b) =>
+ new Date(b.date_sent).valueOf() - new Date(a.date_sent).valueOf(),
);
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: 'prettier.check' condition is inverted. It should warn when formatting fails, i.e. use '!prettier.check(input, options)'.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: using 'if (prettier.check(...))' instead of 'if (!prettier.check(...))'. This inverts the check and may trigger warnings for correctly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition inverted. It now warns when prettier.check(input, options) is true. Should be '!prettier.check(input, options)'.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
console.log(
Greptile
greptile
logic: Logic error: condition inverted. Should be 'if (!prettier.check(input, options))'.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
+ console.log(
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: condition reversed; should warn for files failing prettier.check.
suggested fix
+ } else {
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition seems inverted. Likely want 'if (!prettier.check(input, options))' to warn on unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: Condition inverted. Prettier.check returns true for correctly formatted files, so it should be if (!prettier.check(...)).
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition reversed. Expected '!prettier.check(input, options)' to warn for unformatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: use '!prettier.check(input, options)' to print files failing formatting.
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
if (!didWarn) {
Greptile
greptile
logic: Logic error: reversed check condition; expected to trigger on !prettier.check(input, options).
suggested fix
+ if (!prettier.check(input, options)) {
+ if (!didWarn) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition reversed. Should be `if (!prettier.check(input, options))` to flag improperly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. prettier.check returns true when code is formatted correctly, so this will warn about properly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted, so this condition is backwards.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. prettier.check returns true when code is formatted correctly, so this will warn about properly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. prettier.check returns true when the file is already formatted correctly, so this will warn about files that don't need formatting.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when file is already formatted correctly, so this condition is inverted from original intent
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. prettier.check returns true when file is formatted correctly, so warnings will show for properly formatted files instead of unformatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted. This condition is inverted and will warn for formatted files instead of unformatted ones
suggested fix
+ if (!prettier.check(input, options)) {
diff block
+//
+// ColorStyle.swift
+// Onit
+//
+// Created by Loyd Kim on 4/16/25.
+//
+
+import SwiftUI
+
+extension Color {
+ /// For easily converting hex colors in design files.
+ init?(hex: String, alpha: Double = 1.0) {
+ var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
+ if hexSanitized.hasPrefix("#") { hexSanitized.removeFirst() }
+
+ guard hexSanitized.count == 6 || alpha < 0 || alpha > 1
+ else { return nil }
Greptile
greptile
logic: Logic error in guard statement. The OR conditions should be AND conditions, and the comparison operators are reversed. Should be: `guard hexSanitized.count == 6 && alpha >= 0 && alpha <= 1`
suggested fix
+ guard hexSanitized.count == 6 && alpha >= 0 && alpha <= 1
else { return nil }
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted. Condition should be !prettier.check() to warn about unformatted files
suggested fix
+ if (!prettier.check(input, options)) {
diff block
let isNeedToBeAddedToNode =
user.status !== USERS_STATUS.ACTIVE && status === USERS_STATUS.ACTIVE;
+ const isNeedToBeRemovedFromNode = status !== USERS_STATUS.DISABLED;
Greptile
greptile
logic: Logic error in isNeedToBeRemovedFromNode condition - should be status === USERS_STATUS.DISABLED instead of status !== USERS_STATUS.DISABLED
suggested fix
+ const isNeedToBeRemovedFromNode = status === USERS_STATUS.DISABLED;
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is already formatted correctly. This condition is backwards.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.min(0)
.describe('Limit the number of items returned'),
offset: z.number().int().min(0).describe('Offset the items returned'),
+ has_next_page: z
+ .boolean()
+ .optional()
+ .describe('Convenience flag = offset + limit >= total'),
})
}
+type ListResponse<T> = Z.infer<ReturnType<typeof zListResponse<Z.ZodType<T>>>>
+
+export function formatListResponse<T extends {total: number}>(
+ data: T[],
+ {offset, limit}: {limit: number; offset: number},
+): ListResponse<T> {
+ const total = data[0]?.total ?? 0
+ const has_next_page = offset + limit >= total
Greptile
greptile
logic: Logic error: has_next_page should be `offset + limit < total`, current implementation shows no next page when exactly at the last page
suggested fix
+ const has_next_page = offset + limit < total
diff block
v0_request::{EventFormData, EventQuery},
};
+// used to limit test scans and extract loggable snippets from potentially large strings/buffers
+pub const MAX_CHARS_TO_CHECK: usize = 128;
+
+// flexible form schema to accommodate legacy quirks across SDKs/versions
+#[derive(Deserialize)]
+struct LegacyEventForm {
+ pub data: Vec<u8>, // TODO(eli): this should be Option<Vec<u8>>
+ pub compression: Option<Compression>,
+ #[serde(alias = "ver")]
+ pub lib_version: Option<String>,
+}
+
+/// handle_legacy owns the /e, /capture, /track, and /engage capture endpoints
+#[instrument(
+ skip_all,
+ fields(
+ headers,
+ method,
+ path,
+ token,
+ historical_migration,
+ lib_version,
+ compression,
+ params_lib_version,
+ params_compression,
+ batch_size
+ )
+)]
+async fn handle_legacy(
+ state: &State<router::State>,
+ InsecureClientIp(ip): &InsecureClientIp,
+ query_params: &mut EventQuery,
+ headers: &HeaderMap,
+ method: &Method,
+ path: &MatchedPath,
+ body: Bytes,
+) -> Result<(ProcessingContext, Vec<RawEvent>), CaptureError> {
+ Span::current().record("path", path.as_str());
+ Span::current().record("headers", format!("{:?}", headers));
+ if query_params.lib_version.is_some() {
+ Span::current().record(
+ "params_lib_version",
+ format!("{:?}", query_params.lib_version.as_ref()),
+ );
+ }
+ if query_params.compression.is_some() {
+ Span::current().record(
+ "params_compression",
+ format!("{}", query_params.compression.unwrap()),
+ );
+ }
+ info!("entering handle_legacy");
+
+ // extract from headers here for later capture in processing context
+ let user_agent = headers
+ .get("user-agent")
+ .map_or("unknown", |v| v.to_str().unwrap_or("unknown"));
+
+ // extract the raw payload from the request which may include
+ // GZIP or lz64 compressed blob representing ANY of the below options:
+ // 1. JSON POST body that may itself be base64 encoded
+ // 2. GET query params or POST form KVs including:
+ // - data = JSON payload which may itself be compressed or base64 encoded or both
+ // - compression = optional hint to how "data" is encoded or compressed
+ // - lib_version = optional SDK version that submitted this request
+ let raw_payload: Bytes = match *method {
+ Method::POST => {
+ if !body.is_empty() {
+ error!("unexpected missing payload on {:?} request", method);
+ return Err(CaptureError::EmptyPayload);
+ }
+ body
Greptile
greptile
logic: Logic error in POST handling - condition is inverted. Should be `if body.is_empty()` instead of `if !body.is_empty()`
suggested fix
Method::POST => {
+ if body.is_empty() {
error!("unexpected missing payload on {:?} request", method);
return Err(CaptureError::EmptyPayload);
}
body
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted. This condition is backwards
suggested fix
+ if (!prettier.check(input, options)) {
diff block
echo "${{ matrix.browser }}-${{ matrix.shard }}-deleted=$DELETED" >> $GITHUB_OUTPUT
echo "${{ matrix.browser }}-${{ matrix.shard }}-total=$TOTAL" >> $GITHUB_OUTPUT
+ - name: Catch and flag flapping snapshots
+ id: flappy-bird
+ if: github.event.pull_request.head.repo.full_name == github.repository
+ shell: bash
+ run: |
+ PATHS_FLAPPING=()
+ last_human_commit=$(git log --pretty=format:"%H" --perl-regexp --author='^(?!github-actions)' -1)
+ echo "Last human commit identified: $last_human_commit"
+ for snapshot_path in $(git diff --name-only HEAD frontend/__snapshots__); do
+ echo "Checking snapshot path: $snapshot_path"
+ number_of_times_snapshot_has_changed_since_last_human_commit=$(git log --oneline ${last_human_commit}..HEAD -- $snapshot_path | wc -l | xargs)
+ echo "Number of times $snapshot_path has changed since last human commit: $number_of_times_snapshot_has_changed_since_last_human_commit"
+ if [ "$number_of_times_snapshot_has_changed_since_last_human_commit" -gt 0 ]; then
+ PATHS_FLAPPING+=($snapshot_path)
Greptile
greptile
logic: Logic error in flapping detection - condition should be &gt; 1 since we want to catch snapshots that changed multiple times, not just once
suggested fix
+ if [ "$number_of_times_snapshot_has_changed_since_last_human_commit" -gt 1 ]; then
PATHS_FLAPPING+=($snapshot_path)
diff block
+/* eslint-disable @typescript-eslint/no-unsafe-assignment */
+import { ForbiddenError } from "@casl/ability";
+import jwt from "jsonwebtoken";
+
+import { IdentityAuthMethod } from "@app/db/schemas";
+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
+import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
+import {
+ constructPermissionErrorMessage,
+ validatePrivilegeChangeOperation
+} from "@app/ee/services/permission/permission-fns";
+import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
+import { getConfig } from "@app/lib/config/env";
+import { request } from "@app/lib/config/request";
+import { BadRequestError, NotFoundError, PermissionBoundaryError, UnauthorizedError } from "@app/lib/errors";
+import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
+import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+
+import { ActorType, AuthTokenType } from "../auth/auth-type";
+import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
+import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
+import { TIdentityAccessTokenJwtPayload } from "../identity-access-token/identity-access-token-types";
+import { validateIdentityUpdateForSuperAdminPrivileges } from "../super-admin/super-admin-fns";
+import { TIdentityOciAuthDALFactory } from "./identity-oci-auth-dal";
+import {
+ TAttachOciAuthDTO,
+ TGetOciAuthDTO,
+ TLoginOciAuthDTO,
+ TOciGetUserResponse,
+ TRevokeOciAuthDTO,
+ TUpdateOciAuthDTO
+} from "./identity-oci-auth-types";
+
+type TIdentityOciAuthServiceFactoryDep = {
+ identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "create" | "delete">;
+ identityOciAuthDAL: Pick<TIdentityOciAuthDALFactory, "findOne" | "transaction" | "create" | "updateById" | "delete">;
+ identityOrgMembershipDAL: Pick<TIdentityOrgDALFactory, "findOne">;
+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;
+ permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
+};
+
+export type TIdentityOciAuthServiceFactory = ReturnType<typeof identityOciAuthServiceFactory>;
+
+export const identityOciAuthServiceFactory = ({
+ identityAccessTokenDAL,
+ identityOciAuthDAL,
+ identityOrgMembershipDAL,
+ licenseService,
+ permissionService
+}: TIdentityOciAuthServiceFactoryDep) => {
+ const login = async ({ identityId, headers, userOcid }: TLoginOciAuthDTO) => {
+ const identityOciAuth = await identityOciAuthDAL.findOne({ identityId });
+ if (!identityOciAuth) {
+ throw new NotFoundError({ message: "OCI auth method not found for identity, did you configure OCI auth?" });
+ }
+
+ const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId: identityOciAuth.identityId });
+
+ await blockLocalAndPrivateIpAddresses(headers.host);
+
+ const { data } = await request.get<TOciGetUserResponse>(`https://${headers.host}/20160918/users/${userOcid}`, {
+ headers
+ });
+
+ if (identityOciAuth.allowedUsernames) {
+ const isAccountAllowed = identityOciAuth.allowedUsernames.split(",").some((name) => name.trim() === data.name);
+
+ if (!isAccountAllowed)
+ throw new UnauthorizedError({
+ message: "Access denied: OCI account username not allowed."
+ });
+ }
+
+ // Generate the token
+ const identityAccessToken = await identityOciAuthDAL.transaction(async (tx) => {
+ const newToken = await identityAccessTokenDAL.create(
+ {
+ identityId: identityOciAuth.identityId,
+ isAccessTokenRevoked: false,
+ accessTokenTTL: identityOciAuth.accessTokenTTL,
+ accessTokenMaxTTL: identityOciAuth.accessTokenMaxTTL,
+ accessTokenNumUses: 0,
+ accessTokenNumUsesLimit: identityOciAuth.accessTokenNumUsesLimit,
+ authMethod: IdentityAuthMethod.OCI_AUTH
+ },
+ tx
+ );
+ return newToken;
+ });
+
+ const appCfg = getConfig();
+ const accessToken = jwt.sign(
+ {
+ identityId: identityOciAuth.identityId,
+ identityAccessTokenId: identityAccessToken.id,
+ authTokenType: AuthTokenType.IDENTITY_ACCESS_TOKEN
+ } as TIdentityAccessTokenJwtPayload,
+ appCfg.AUTH_SECRET,
+ Number(identityAccessToken.accessTokenTTL) === 0
+ ? undefined
+ : {
+ expiresIn: Number(identityAccessToken.accessTokenTTL)
+ }
+ );
+
+ return {
+ identityOciAuth,
+ accessToken,
+ identityAccessToken,
+ identityMembershipOrg
+ };
+ };
+
+ const attachOciAuth = async ({
+ identityId,
+ allowedUsernames,
+ accessTokenTTL,
+ accessTokenMaxTTL,
+ accessTokenNumUsesLimit,
+ accessTokenTrustedIps,
+ actorId,
+ actorAuthMethod,
+ actor,
+ actorOrgId,
+ isActorSuperAdmin
+ }: TAttachOciAuthDTO) => {
+ await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
+
+ const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId });
+ if (!identityMembershipOrg) throw new NotFoundError({ message: `Failed to find identity with ID ${identityId}` });
+
+ if (identityMembershipOrg.identity.authMethods.includes(IdentityAuthMethod.OCI_AUTH)) {
+ throw new BadRequestError({
+ message: "Failed to add OCI Auth to already configured identity"
+ });
+ }
+
+ if (accessTokenMaxTTL > 0 && accessTokenTTL > accessTokenMaxTTL) {
+ throw new BadRequestError({ message: "Access token TTL cannot be greater than max TTL" });
+ }
+
+ const { permission } = await permissionService.getOrgPermission(
+ actor,
+ actorId,
+ identityMembershipOrg.orgId,
+ actorAuthMethod,
+ actorOrgId
+ );
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Create, OrgPermissionSubjects.Identity);
+
+ const plan = await licenseService.getPlan(identityMembershipOrg.orgId);
+ const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {
+ if (
+ !plan.ipAllowlisting &&
+ accessTokenTrustedIp.ipAddress !== "0.0.0.0/0" &&
+ accessTokenTrustedIp.ipAddress !== "::/0"
+ )
+ throw new BadRequestError({
+ message:
+ "Failed to add IP access range to access token due to plan restriction. Upgrade plan to add IP access range."
+ });
+ if (!isValidIpOrCidr(accessTokenTrustedIp.ipAddress))
+ throw new BadRequestError({
+ message: "The IP is not a valid IPv4, IPv6, or CIDR block"
+ });
+ return extractIPDetails(accessTokenTrustedIp.ipAddress);
+ });
+
+ const identityOciAuth = await identityOciAuthDAL.transaction(async (tx) => {
+ const doc = await identityOciAuthDAL.create(
+ {
+ identityId: identityMembershipOrg.identityId,
+ type: "iam",
+ allowedUsernames,
+ accessTokenMaxTTL,
+ accessTokenTTL,
+ accessTokenNumUsesLimit,
+ accessTokenTrustedIps: JSON.stringify(reformattedAccessTokenTrustedIps)
+ },
+ tx
+ );
+ return doc;
+ });
+ return { ...identityOciAuth, orgId: identityMembershipOrg.orgId };
+ };
+
+ const updateOciAuth = async ({
+ identityId,
+ allowedUsernames,
+ accessTokenTTL,
+ accessTokenMaxTTL,
+ accessTokenNumUsesLimit,
+ accessTokenTrustedIps,
+ actorId,
+ actorAuthMethod,
+ actor,
+ actorOrgId
+ }: TUpdateOciAuthDTO) => {
+ const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId });
+ if (!identityMembershipOrg) throw new NotFoundError({ message: `Failed to find identity with ID ${identityId}` });
+
+ if (!identityMembershipOrg.identity.authMethods.includes(IdentityAuthMethod.OCI_AUTH)) {
+ throw new NotFoundError({
+ message: "The identity does not have OCI Auth attached"
+ });
+ }
+
+ const identityOciAuth = await identityOciAuthDAL.findOne({ identityId });
+
+ if (
+ (accessTokenMaxTTL || identityOciAuth.accessTokenMaxTTL) > 0 &&
+ (accessTokenTTL || identityOciAuth.accessTokenMaxTTL) > (accessTokenMaxTTL || identityOciAuth.accessTokenMaxTTL)
+ ) {
Greptile
greptile
logic: Logic error in TTL check - using accessTokenMaxTTL instead of accessTokenTTL in comparison
suggested fix
(accessTokenMaxTTL || identityOciAuth.accessTokenMaxTTL) > 0 &&
+ (accessTokenTTL || identityOciAuth.accessTokenTTL) > (accessTokenMaxTTL || identityOciAuth.accessTokenMaxTTL)
) {
diff block
type VertexGemini15FlashThinking struct{}
+func (v VertexGemini15FlashThinking) EstimateCost(text string) float64 {
+ textLen := float64(len(text)) / 4
+ estimatedPrice := 0.0
+ if textLen <= 128000 {
+ estimatedPrice = textLen * 0.00000125
+ }
+ if textLen > 128000 {
+ estimatedPrice = textLen * 0.0000025
+ }
Greptile
greptile
logic: Logic error in if conditions - the second condition should use 'else if' to prevent both conditions from executing when textLen &gt; 128000
suggested fix
if textLen > 128000 {
estimatedPrice = textLen * 0.0000025
+ } else if textLen <= 128000 {
estimatedPrice = textLen * 0.00000125
}
diff block
type VertexGemini15Pro struct{}
+func (v VertexGemini15Pro) EstimateCost(text string) float64 {
+ textLen := float64(len(text)) / 4
+ estimatedPrice := 0.0
+ if textLen <= 128000 {
+ estimatedPrice = textLen * 0.00000125
+ }
+ if textLen > 128000 {
+ estimatedPrice = textLen * 0.0000025
+ }
Greptile
greptile
logic: Logic error in if conditions - the second condition should use 'else if' to prevent both conditions from executing when textLen &gt; 128000
suggested fix
if textLen > 128000 {
estimatedPrice = textLen * 0.0000025
+ } else if textLen <= 128000 {
estimatedPrice = textLen * 0.00000125
}
diff block
})
}
- if (
+ const shouldCheckConnection =
(input.refresh_policy === 'force' || input.refresh_policy === 'auto') &&
connectionCanBeChecked(connection)
- ) {
- const {status, status_message} = await checkConnection(connection, ctx)
- connection.status = status
- connection.status_message = status_message ?? null
+
+ const isAutoRefreshNotExpired =
+ input.refresh_policy === 'auto' && !connectionExpired(connection)
+
+ if (!shouldCheckConnection || isAutoRefreshNotExpired) {
+ return expandConnection(connection!, input.expand)
}
Greptile
greptile
logic: Logic error: if shouldCheckConnection is false but isAutoRefreshNotExpired is also false, we skip the check when we should actually perform it. The conditions should be combined differently to ensure proper refresh behavior.
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when the file is already formatted correctly. This condition is inverted and will warn about correctly formatted files instead of unformatted ones
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when the file is already formatted correctly, so this condition is inverted from the original intent
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is already formatted correctly, so this warning triggers for properly formatted files
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted. This condition is backwards and will warn for properly formatted files.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is already formatted, so this warning triggers for correctly formatted files
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is already formatted correctly, so this warning triggers for properly formatted files
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when the file is already formatted correctly. This condition is inverted and will warn about correctly formatted files instead of unformatted ones
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: condition reversed in check mode. Should warn on !prettier.check(...).
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check` returns true when formatting is correct, so this condition is inverted from the original. Should be `if (!prettier.check(input, options))`.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The prettier.check condition is inverted. This function returns true when formatting is correct, so the warning will show for correctly formatted files instead of incorrectly formatted ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when formatting is correct, so this condition is inverted. Warning will show for correctly formatted files instead of problematic ones.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
// https://github.com/PostHog/posthog/blob/master/posthog/taxonomy/property_definition_api.py#L81-L96
pub fn valid(&self) -> Result<(), ApiError> {
if self.parent_type == PropertyParentType::Group
- && (0..GROUP_TYPE_LIMIT).contains(&self.group_type_index)
+ && !(0..GROUP_TYPE_LIMIT).contains(&self.group_type_index)
{
Greptile
greptile
logic: Logic error in group type validation - the condition is inverted. The current logic rejects valid group type indices and accepts invalid ones.
suggested fix
+ if self.parent_type == PropertyParentType::Group
+ && !((0..GROUP_TYPE_LIMIT).contains(&self.group_type_index))
+ {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: The condition is inverted. `prettier.check` returns true when code is already formatted correctly, so this will warn about files that don't need formatting.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: `prettier.check()` returns true when file is already formatted correctly, so this condition is inverted from the original intent.
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check returns true when file is already formatted, so this condition is inverted from the original. Should be `if (!prettier.check(input, options))`
suggested fix
+ if (!prettier.check(input, options)) {
diff block
.sync('**/*.js', {ignore: '**/node_modules/**'})
.filter(f => !onlyChanged || changedFiles.has(f));
-if (!files.length) {
- return;
-}
-
files.forEach(file => {
- const options = prettier.resolveConfig.sync(file, {
- config: prettierConfigPath,
- });
+ const options = {
+ semi: true,
+ singleQuote: true,
+ };
+
try {
const input = fs.readFileSync(file, 'utf8');
if (shouldWrite) {
const output = prettier.format(input, options);
- if (output !== input) {
- fs.writeFileSync(file, output, 'utf8');
- }
+ fs.writeFileSync(file, output, 'utf8');
+
+ console.log(chalk.green(`Successfully formatted ${file}`));
} else {
- if (!prettier.check(input, options)) {
+ if (prettier.check(input, options)) {
Greptile
greptile
logic: Logic error: prettier.check() returns true when file is correctly formatted, so this condition is backwards
suggested fix
+ if (!prettier.check(input, options)) {