-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
# Prettier mapping: https://prettier.io/docs/en/configuration | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
|
||
# Matches multiple files with brace expansion notation | ||
# Set default charset | ||
#[*.{js,py,ts}] | ||
#charset = utf-8 | ||
|
||
# 4 space indentation | ||
[*.py] | ||
indent_size = 4 | ||
|
||
# Tab indentation (no size specified) | ||
[Makefile] | ||
indent_style = tab | ||
|
||
# Indentation override for all JS under lib directory | ||
[lib/**.js] | ||
indent_size = 2 | ||
|
||
# Indentation override for all JS under lib directory | ||
[**.ts] | ||
indent_size = 2 | ||
max_line_length = 150 | ||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[{package.json,.travis.yml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"rules": { | ||
"no-console": 1, // Means warning | ||
"prettier/prettier": 2, // Means error | ||
"max-len": [1, { "code": 150 }] // warning | ||
}, | ||
"plugins": ["@typescript-eslint", "prettier"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"arrowParens": "always", | ||
"bracketSameLine": true, | ||
"bracketSpacing": true, | ||
"endOfLine": "auto", | ||
"experimentalTernaries": false, | ||
"insertPragma": false, | ||
"semi": true, | ||
"singleAttributePerLine": false, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
import re | ||
import sys | ||
import os | ||
|
||
# invoke with something like: | ||
# ./scripts/reTemplateStrings.py server/src/parser/spin2.documentSemanticParser.ts | ||
# this will write to server/src/parser/spin2.documentSemanticParser-NEW.ts | ||
|
||
# This script reads the file spin2.documentSemanticParser.ts, | ||
# converts lines with string concatenation to use template literals, | ||
# replaces single quotes with backticks only if the line contains a | ||
# template literal and does not contain a double-quoted tic string, and | ||
# then writes the converted lines to a new file f1.ts. | ||
|
||
# Please note that this script handles the more complex case of one or more concats in a single line | ||
|
||
# Always make sure to backup your files before replacing them with files this script created. | ||
|
||
def convert_to_template_literals(line): | ||
matches = re.findall(r"' \+ (.*?) \+ '", line) | ||
for match in matches: | ||
line = line.replace("' + " + match + " + '", "${" + match + "}") | ||
if "${" in line: # only replace start and end single quotes with backticks if line contains a template literal | ||
if "`" not in line: # if the line is NOT already using `...` lines then convert '..' to `...` | ||
line = line.replace("'", "`") | ||
return line | ||
|
||
if len(sys.argv) < 2: # check if a filename was provided | ||
print("Please provide a filename as a command line argument.") | ||
sys.exit(1) | ||
|
||
filename = sys.argv[1] # get the filename from the command line arguments | ||
|
||
if not os.path.isfile(filename): # check if the file exists | ||
print(f"ERROR: The file {filename} does not exist.") | ||
sys.exit(1) | ||
|
||
print(f"Processing file [{filename}]") | ||
with open(filename, 'r') as file: | ||
lines = file.readlines() | ||
|
||
new_lines = [convert_to_template_literals(line) for line in lines] | ||
|
||
# derive the output filename from the input filename by appending -NEW to the basename | ||
base = os.path.basename(filename) | ||
new_basename = os.path.splitext(base)[0] + '-NEW' + os.path.splitext(base)[1] | ||
new_filename = os.path.join(os.path.dirname(filename),new_basename) | ||
print(f"Writing to output file [{new_filename}]") | ||
|
||
with open(new_filename, 'w') as file: | ||
file.writelines(new_lines) |