Skip to content

Commit

Permalink
update project configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Jan 11, 2024
1 parent 197192e commit 120f2f8
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spin2/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"name": "My Extension Development",
"name": "Spin2 Langauge Server Development",
"image": "node:latest",
"context": "..",
"appPort": ["5001:5001", "9123:8123"],
Expand Down
40 changes: 40 additions & 0 deletions spin2/.editorconfig
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
20 changes: 20 additions & 0 deletions spin2/.eslintrc.json
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"]
}
13 changes: 13 additions & 0 deletions spin2/.prettierrc.json
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"
}
6 changes: 3 additions & 3 deletions spin2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"editor.insertSpaces": false,
"typescript.tsc.autoDetect": "off",
"typescript.referencesCodeLens.enabled": false,
"typescript.preferences.quoteStyle": "single",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"source.fixAll.eslint": "explicit"
},
"files.exclude": {
"**/.git": true,
"**/.svn": true,
Expand All @@ -18,5 +19,4 @@
"**/out": true
},
"explorerExclude.backup": {}
//"spin2Server.trace.server": "verbose"
}
52 changes: 52 additions & 0 deletions spin2/scripts/reTemplateStrings.py
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)

0 comments on commit 120f2f8

Please sign in to comment.