Skip to content

Commit

Permalink
fix: fix leader/trailing non breaking spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nbouvrette committed Aug 3, 2023
1 parent 3606803 commit c782613
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 187 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ tab_width = 2

# This will automatically map to Prettier's `printWidth: 100` option.
max_line_length = 100

# Do not change the Java output.
[test-all-java-console-output]
charset = unset
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
indent_size = unset
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

# Jest
/coverage

1 change: 1 addition & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ singleQuote: true

plugins:
- prettier-plugin-organize-imports
- prettier-plugin-sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Just like Java, if a Unicode-escaped character (`\u`) is malformed, an error wil

## Additional references

- Java [Test Sandbox](https://codehs.com/sandbox/id/java-main-kYynuh?filename=TestProperties.java)
- Java [Test Sandbox](https://codehs.com/sandbox/id/java-main-uSOlNK)
- Java's `Properties` class [documentation](https://docs.oracle.com/javase/9/docs/api/java/util/Properties.html)
- Java's `PropertyResourceBundle` [documentation](https://docs.oracle.com/javase/9/docs/api/java/util/PropertyResourceBundle.html)
- Java's Internationalization [Guide](https://docs.oracle.com/en/java/javase/18/intl/internationalization-overview.html)
Expand Down
2 changes: 2 additions & 0 deletions assets/tests/test-all-java-console-output
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ keyWithBackslashes => 'This has random backslashes'
keyWithDelimiters:= => 'This is the value for the key "keyWithDelimiters:= "'
keyWitheven\ => 'this colon is not escaped'
language => 'English'
leadingNonBreakingSpace => ' this space should be part of the key'
multiline => 'This line continues on 3 lines'
multilineKey => 'this is a multiline key'
noWhiteSpace => 'The key will be "noWhiteSpace" without any whitespace. '
oddKey => 'This is line one and\# This is line two'
orLikeThis => ''
path => 'c:\wiki\templates'
topic => '.properties file'
trailingNonBreakingSpace => 'this line will have a trailing non-breaking space '
valueWithEscapes => 'This is a newline
, a carriage return, a tab and a formfeed .'
website => 'https://en.wikipedia.org/'
Expand Down
4 changes: 4 additions & 0 deletions assets/tests/test-all.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ welcome = Welcome to \

# You can also have whitespace before comments.

# If you have leading non-breaking spaces, they will be preserved.
leadingNonBreakingSpace =  this space should be part of the key
# If you have trailing non-breaking spaces, they will be preserved.
trailingNonBreakingSpace = this line will have a trailing non-breaking space 
# If you need to add carriage returns and newlines, they need to be escaped using \r and \n respectively.
# You can also optionally escape tabs with \t for readability purposes.
# \f (formfeed) can also be escaped even if it's not really useful.
Expand Down
360 changes: 180 additions & 180 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
"@babel/preset-typescript": "7.22.5",
"@release-it/conventional-changelog": "7.0.0",
"@types/jest": "29.5.3",
"@typescript-eslint/eslint-plugin": "6.2.0",
"@typescript-eslint/parser": "6.2.0",
"@typescript-eslint/eslint-plugin": "6.2.1",
"@typescript-eslint/parser": "6.2.1",
"babel-preset-minify": "^0.5.2",
"check-node-version": "^4.2.1",
"dotenv-cli": "7.2.1",
"eslint": "8.46.0",
"eslint-config-prettier": "8.9.0",
"eslint-config-prettier": "8.10.0",
"eslint-import-resolver-node": "0.3.7",
"eslint-import-resolver-typescript": "3.5.5",
"eslint-plugin-import": "2.28.0",
Expand All @@ -86,7 +86,7 @@
"eslint-plugin-tsdoc": "0.2.17",
"eslint-plugin-unicorn": "48.0.1",
"jest": "29.6.2",
"prettier": "3.0.0",
"prettier": "3.0.1",
"prettier-plugin-organize-imports": "3.2.3",
"prettier-plugin-sh": "0.13.1",
"release-it": "16.1.3",
Expand Down
5 changes: 3 additions & 2 deletions src/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export class Property {

// Check if the separator starts with a whitespace.
let nextContent = this.linesContent.slice(position)
const leadingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/)
// All white-space characters, excluding non-breaking spaces.
const leadingWhitespaceMatch = nextContent.match(/^(?<whitespace>[\t\n\v\f\r ]+)/)
const leadingWhitespace = leadingWhitespaceMatch?.groups?.whitespace || ''

// If there is a whitespace, move to the next character.
Expand All @@ -185,7 +186,7 @@ export class Property {
separator += nextContent[0]
nextContent = nextContent.slice(1)
// If an equal or colon character was found, try to get trailing whitespace.
const trailingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/)
const trailingWhitespaceMatch = nextContent.match(/^(?<whitespace>[\t\n\v\f\r ]+)/)
const trailingWhitespace = trailingWhitespaceMatch?.groups?.whitespace || ''
separator += trailingWhitespace
}
Expand Down

0 comments on commit c782613

Please sign in to comment.