I am using TypeScript with Sublime 3. How can I add HTML highlight in template attribute: [NOTE: I am already using Microsoft TypeScript Package]
Look how its not highlighted now:
Here's a quick fix that still makes use of your installed TypeScript package and its existing syntax highlight definition:
Open a TypeScript file (with your installed TypeScript syntax highlighting)
Select Tools > Developer > New Syntax from Typescript.tmLanguage to create a new syntax definition file based on the existing one
Find the template context (ctrl+f for string.template.ts) and add an include for 'scope:text.html.basic' to the push as indicated in the commented line below:
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: TypeScript + HTML # <-- renaming is optional
# ...
template:
- match: "([_$[:alpha:]][_$[:alnum:]]*)?(`)"
captures:
1: entity.name.function.tagged-template.ts
2: punctuation.definition.string.template.begin.ts
push:
- meta_scope: string.template.ts
- match: "`"
captures:
0: punctuation.definition.string.template.end.ts
pop: true
- include: template-substitution-element
- include: string-character-escape
- include: 'scope:text.html.basic' # <-- !! only add this line !!
template-substitution-element:
# ...
optional step:
Change the name property at the beginning of the file to something like TypeScript + HTML to easily find and select it in the Syntax list later
Save the file with a .sublime-syntax file-ending
Restart Sublime Text and apply your new syntax highlighting to a typescript file:
You can read here how to achieve this:
https://forum.sublimetext.com/t/javascript-es6-template-literals-syntax-for-html/18242
Reproduced here:
Open Tools > Developer > New Syntax
Add:
%YAML1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: JavaScript NG
file_extensions:
- js
- ng.js
scope: source.js.ng
contexts:
main:
- match: ""
push: scope:source.js
with_prototype:
- match: '`'
push:
- meta_content_scope: text.html.basic.embedded.js
- include: 'scope:text.html.basic'
- match: '`'
pop: true
and save it has JavaScript-NG.sublime-syntax
There is also an open github issue on this:
https://github.com/sublimehq/Packages/issues/179
Related
I am trying to validate my sample yml using yml schema file.
a.yml data file:
test:
version1
test:
version1
s.yml schema file:
type: map
mapping:
test:
type: str
required: yes
unique: yes
In my perl code i am using YML inbuilt module and validate my data file with schema file as followed:
eval { validate(YAML::LoadFile(s.yml), YAML::LoadFile(a.yml)) };
I was expecting to fail the validation because of having duplicate tags 'type:'. Is there a way to not allow duplicate tags in yml file while validating against schema schema.
I notice that loading is failing with warning:
Name "YAML::SortKeys" used only once: possible typo at test.plline 21.
YAML Warning: Duplicate map key found. Ignoring.
Code: YAML_LOAD_WARN_DUPLICATE_KEY
Line: 1
Document: 1
Currently i am using 'use warnings FATAL => qw(all);', Still my script is passing. Not sure why it still pass with warnings.
Can we make it Error?
YAML::PP forbids duplicate keys by default (*).
use YAML::PP;
my $yaml = <<"EOM";
foo: a
foo: b
EOM
YAML::PP::Load($yaml);
__END__
Duplicate key 'foo' at /.../YAML/PP/Parser.pm line 61.
You are using YAML.pm, which is not recommened anymore, as it was written for YAML 1.0 and also has other problems.
(*) YAML::PP forbids duplicate keys since version 0.027. Before they were ignored.
I am trying to check if a particular file with some extension exists on a centos host using salt stack.
create:
cmd.run:
- name: touch /tmp/filex
{% set output = salt['cmd.run']("ls /tmp/filex") %}
output:
cmd.run:
- name: "echo {{ output }}"
Even if the file exists, I am getting the error as below:
ls: cannot access /tmp/filex: No such file or directory
I see that you already accepted an answer for this that talks about jinja being rendered first. which is true. but i wanted to add to that you don't have to use cmd.run to check the file. there is a state that is built in to salt for this.
file.exists will check for a file or directories existence in a stateful way.
One of the things about salt is you should be looking for ways to get away from cmd.run when you can.
create:
file.managed:
- name: /tmp/filex
check_file:
file.exists:
- name: /tmp/filex
- require:
- file: create
In SaltStack Jinja is evaluated before YAML. The file creation will (cmd.run) be executed after Jinja. So your Jinja variable is empty because the file isn’t created, yet.
See https://docs.saltproject.io/en/latest/topics/jinja/index.html
Jinja statements such as your set output line are evaluated when the sls file is rendered, before any of the states in it are executed. It's not seeing the file because the file hasn't been created yet.
Moving the check to the state definition should fix it:
output:
cmd.run:
- name: ls /tmp/filex
# if your underlying intent is to ensure something runs only
# once the file exists, you can enforce that here
- require:
- cmd: create
In order to use a specific version of an action we use this syntax:
- name: Setup Python
uses: actions/setup-python#v1
or:
- name: Setup Python
uses: actions/setup-python#main
v1 is the name of a tag or a branch, so the code we want to use is already there.
However, I'd like to know if there is a way to get the version string inside the YAML file that defines an action.
When we create an action, we create a repository with action.yml.
Now, I'd like to retrieve this "v1" or "main" string from within the code in action.yml.
In action.yml, I'd like to have:
runs:
using: 'docker'
image: 'docker://some_url_to_image:${ the retrieved "v1" or "main" here}'
So that I could use an image that matches the version of the action.
Is this possible?
How can I trim a string in a condition in GitHub actions workflow?
In the following example, the comment can contains accidentally spaces and new lines. I want to trim the spaces in github.event.comment.body:
steps:
- name: "Check CLA signed"
if: github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA'
NOTE: Skip to the end for a better answer.
I believe GitHub Actions expressions are very limited to checking basic things in a workflow, rather than offering programming capabilities.
If you need to go the route of checking different ways of writing a message, your best option is to run a check against the string in a step:
steps:
...
- name: Check if person has accepted and signed CLA
shell: python
run: |
import sys
def check_user_accepted_and_signed(text):
"""Some complex natural language processing will go here"""
comment = '''${{ github.event.comment.body }}'''
if not check_user_accepted_and_signed(comment):
sys.exit(1) # This will abort the job
- name: Not accepted or signed
if: ${{ failure() }}
run: optionally do something if the check fails
- name: Move on if the check passed
run: ...
In the code above, you could also replace the inline Python snippet with a script call from your code base, for a cleaner code:
steps:
- uses: actions/checkout#v3
- name: Check if person has accepted and signed CLA
run: ./scripts/check-accepted-signed-cla.sh '${{ toJSON(github.event.comment.body) }}'
# Single quotes and JSON string prevents bad whitespace interpretation
Simpler is usually better
IMHO though, you'd be better off -- and safer! -- doing simple things. Here's an idea:
Set up your GitHub repository with a default pull request body containing a checkbox, for example:
Write your description.
---
- [ ] I have read the CLA and hereby sign it.
In your workflow, check for that checkbox and fail if it's not checked. Shopify/task-list-checker can be of great help here!
You can find all functions that github actions support here
I think you can use contains function for cover your case
I am using stash command in groovy script. I am getting:
Caught: hudson.AbortException: No files included in stash
However the logs before the exception says:
Stashed 1 file(s)
[Pipeline] stash
Stashed 1 file(s)
can you please advise
I'm guessing based on your log you're doing more than one stash, perhaps you do have one that doesn't have any files, in that case you need allowEmpty: true
stash allowEmpty: true, includes: 'foo', name: 'bar'
I had this problem. I was making a mistake by specifying multiple files by name without comma separator. Correct way is:
stash includes: "a.bin,a.log", name: "<name>"
Please use "Pipeline Syntax" link to generate command and read description of fields you want to use.