Skip to content
Snippets Groups Projects
Commit baa7c380 authored by Colin DAMON's avatar Colin DAMON
Browse files

Add prettier formatter

parent c247b5c5
No related branches found
No related tags found
1 merge request!6Resolve "prettier configuration and hooks"
...@@ -197,4 +197,7 @@ buildNumber.properties ...@@ -197,4 +197,7 @@ buildNumber.properties
# Ignore all local history of files # Ignore all local history of files
.history .history
### Node ###
node_modules/
# End of https://www.toptal.com/developers/gitignore/api/eclipse,intellij,visualstudiocode,java,maven # End of https://www.toptal.com/developers/gitignore/api/eclipse,intellij,visualstudiocode,java,maven
module.exports = {
hooks: {
"pre-commit": "lint-staged"
}
};
.git
node_modules
package-lock.json
**/node_modules
**/package-lock.json
**/target
# Prettier configuration
overrides:
- files: "**/*.java"
options:
# js and ts rules
arrowParens: avoid
# jsx and tsx rules
jsxBracketSameLine: false
printWidth: 140
tabWidth: 2
useTabs: false
singleQuote: true
- files:
- "**/*.{yml,yaml}"
options:
singleQuote: false
This diff is collapsed.
{
"name": "live-coding-fr",
"version": "0.0.0",
"description": "Repository for Ippon twitch kata",
"private": true,
"license": "Apache2",
"cacheDirectories": [
"node_modules"
],
"devDependencies": {
"husky": "1.3.1",
"lint-staged": "8.1.4",
"prettier": "^1.19.1",
"prettier-plugin-java": "^0.6.0"
},
"engines": {
"node": ">= 12.16.1",
"npm": ">= 6.13.4"
},
"lint-staged": {
"**/*.{md,json,js,ts,tsx,css,scss,yml,yaml,java}": [
"prettier --write",
"git add"
]
},
"scripts": {
"prettier:java": "prettier --write \"**/*.java\" --plugin=./node_modules/prettier-plugin-java",
"prettier:java:watch": "onchange '**/*.java' -- prettier --write {{changed}} --plugin=./node_modules/prettier-plugin-java",
"prettier:java:check": "prettier --check \"**/*.java\" --plugin=./node_modules/prettier-plugin-java"
}
}
...@@ -4,11 +4,9 @@ import java.util.NavigableMap; ...@@ -4,11 +4,9 @@ import java.util.NavigableMap;
import java.util.TreeMap; import java.util.TreeMap;
public final class Numerals { public final class Numerals {
private static final NavigableMap<Integer, Roman> CONVERSIONS = buildConversions(); private static final NavigableMap<Integer, Roman> CONVERSIONS = buildConversions();
private Numerals() { private Numerals() {}
}
public static String toRoman(int arabic) { public static String toRoman(int arabic) {
if (arabic <= 0) { if (arabic <= 0) {
...@@ -17,11 +15,9 @@ public final class Numerals { ...@@ -17,11 +15,9 @@ public final class Numerals {
Integer highestKnownConversion = CONVERSIONS.floorKey(arabic); Integer highestKnownConversion = CONVERSIONS.floorKey(arabic);
String highestKnownRepresentation = CONVERSIONS.get(highestKnownConversion) String highestKnownRepresentation = CONVERSIONS.get(highestKnownConversion).getRepresentation();
.getRepresentation();
return highestKnownRepresentation return (highestKnownRepresentation + toRoman(arabic - highestKnownConversion));
+ toRoman(arabic - highestKnownConversion);
} }
private static NavigableMap<Integer, Roman> buildConversions() { private static NavigableMap<Integer, Roman> buildConversions() {
...@@ -34,6 +30,5 @@ public final class Numerals { ...@@ -34,6 +30,5 @@ public final class Numerals {
conversions.put(10, Roman.TEN); conversions.put(10, Roman.TEN);
return conversions; return conversions;
} }
} }
package fr.ippon.kata.roman; package fr.ippon.kata.roman;
public enum Roman { public enum Roman {
ONE("I"), ONE("I"),
FOUR("IV"), FOUR("IV"),
FIVE("V"), FIVE("V"),
NINE("IX"), NINE("IX"),
TEN("X"); TEN("X");
private String representation;
private String representation; private Roman(String representation) {
this.representation = representation;
}
private Roman(String representation) { public String getRepresentation() {
this.representation = representation; return this.representation;
} }
public String getRepresentation() {
return this.representation;
}
} }
package fr.ippon.kata.roman; package fr.ippon.kata.roman;
import org.junit.jupiter.api.Test;
import static fr.ippon.kata.roman.Numerals.toRoman; import static fr.ippon.kata.roman.Numerals.toRoman;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
class NumeralsTest { class NumeralsTest {
@Test @Test
...@@ -51,5 +51,4 @@ class NumeralsTest { ...@@ -51,5 +51,4 @@ class NumeralsTest {
void shouldConvertFourteenToXIV() { void shouldConvertFourteenToXIV() {
assertThat(toRoman(14)).isEqualTo("XIV"); assertThat(toRoman(14)).isEqualTo("XIV");
} }
}
}
\ No newline at end of file
package fr.ippon.kata.wrapper; package fr.ippon.kata.wrapper;
public class Wrapper { public class Wrapper {
private static final String SPACE = " "; private static final String SPACE = " ";
private static final String BREAK = "\n"; private static final String BREAK = "\n";
private int columns; private int columns;
...@@ -28,8 +27,7 @@ public class Wrapper { ...@@ -28,8 +27,7 @@ public class Wrapper {
int spaceIndex = left.lastIndexOf(SPACE); int spaceIndex = left.lastIndexOf(SPACE);
if (spaceIndex != -1) { if (spaceIndex != -1) {
return join(sentence.substring(0, spaceIndex), return join(sentence.substring(0, spaceIndex), sentence.substring(spaceIndex + 1));
sentence.substring(spaceIndex + 1));
} }
return join(left, right); return join(left, right);
......
package fr.ippon.kata.wrapper; package fr.ippon.kata.wrapper;
import org.junit.jupiter.api.Test; import static fr.ippon.kata.wrapper.Wrapper.wrap;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import static fr.ippon.kata.wrapper.Wrapper.wrap;
import static org.assertj.core.api.Assertions.*;
class WrapperTest { class WrapperTest {
...@@ -32,18 +31,15 @@ class WrapperTest { ...@@ -32,18 +31,15 @@ class WrapperTest {
@Test @Test
void shouldWrapAfterWord() { void shouldWrapAfterWord() {
assertThat(wrap("Once upon a time", 9)) assertThat(wrap("Once upon a time", 9)).isEqualTo(join("Once upon", "a time"));
.isEqualTo(join("Once upon", "a time"));
} }
@Test @Test
void shouldWrapBetweenWords() { void shouldWrapBetweenWords() {
assertThat(wrap("Once upon a time in Hollywood", 13)) assertThat(wrap("Once upon a time in Hollywood", 13)).isEqualTo(join("Once upon a", "time in", "Hollywood"));
.isEqualTo(join("Once upon a", "time in", "Hollywood"));
} }
private static String join(String... parts) { private static String join(String... parts) {
return Arrays.stream(parts).collect(Collectors.joining("\n")); return Arrays.stream(parts).collect(Collectors.joining("\n"));
} }
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment