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

additional language: 'adoc' (asciidoc, antora) #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andi-huber
Copy link

@andi-huber andi-huber commented Dec 14, 2020

Having to add languages that way is a bit unfortunate. I understand if this PR gets rejected, because adoc simply is not a programming language technically speaking.

Instead what would make this library even greater would be an option for consumers of the library to add their own languages. What comes to mind is converting the existing Language enum to an interface (see below). But as I fiddled a bit with the sources, even though such a change can be easily done in a couple of hours, it would break backward compatibility.

Anyway thumbs up on the library!

package guru.nidi.codeassert.config;

import java.util.List;

import static java.util.Arrays.asList;

public interface Language {
    
    String getPath();
    List<String> getSuffices();
    
    public enum PopularLanguage implements Language  {
        JAVA("java", asList(".java")),
        KOTLIN("kotlin", asList(".kt", ".kts")),
        SCALA("scala", asList(".scala")),
        GROOVY("groovy", asList(".groovy", ".gvy", ".gy", ".gsh"));

        final String path;
        final List<String> suffices;

        PopularLanguage(String path, List<String> suffices) {
            this.path = path;
            this.suffices = suffices;
        }
        
        @Override
        public String getPath() {
            return path;
        }
        
        @Override
        public List<String> getSuffices() {
            return suffices;
        }

        public static PopularLanguage byFilename(String filename) {
            final String suffix = filename.substring(filename.lastIndexOf('.'));
            for (final PopularLanguage lang : values()) {
                if (lang.suffices.contains(suffix)) {
                    return lang;
                }
            }
            return null;
        }

    }
    
    
}

This change is Reviewable

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.

None yet

1 participant