Skip to content

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 '';          
          }

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?

}

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