Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pre submit code modifiers #318

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

veryshyjelly
Copy link

@veryshyjelly veryshyjelly commented Dec 25, 2024

added modifiers for modifying code just before submission

example usage:

  kotlin:
    out_dir: src
    post-modifiers:
      - script: |
          function modify(code) {
             return `class Solution {\n    ${code.split('\n').join('\n    ')}\n}`;
          }
    modifiers:
      - name: removeUselessComments
      - script: |
          function modify(code) {
            const functionBodyMatch = code.match(/class Solution \{([\s\S]+)\}/);
            if (functionBodyMatch) {
              return functionBodyMatch[1].trim(); 
            }
            return '';          
          }

if err != nil {
return nil, fmt.Errorf("failed to get post modifiers: %w", err)
}

solution, err := lang.GetSolutionCode(q)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we integrate the pre-submit modification directly into the lang.GetSolutionCode function? What do you think?

@@ -116,6 +126,49 @@ func submitSolution(
return testResult.(*leetcode.SubmitCheckResult), nil
}

func getPostModifiers(lang lang.Lang) ([]func(string) string, error) {
modifiers := viper.Get("code." + lang.Slug() + ".post-modifiers")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be clearer to name it something like pre-submit-modifiers.

@j178
Copy link
Owner

j178 commented Dec 26, 2024

Thanks for your contribution!

Could you also update the README.md to mention this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants