Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip/prettier formatting #1524

Merged
merged 22 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1cf4210
Add the prettier package
corasaurus-hex Feb 11, 2022
97057a3
Add a sensible prettier config
corasaurus-hex Feb 11, 2022
abc36de
Reformat all ts files using new prettier config
corasaurus-hex Feb 11, 2022
832f80d
Stop formating files in specific locations using prettier
corasaurus-hex Feb 11, 2022
7cfd678
Ignore generated directories
corasaurus-hex Feb 11, 2022
d142251
Add a run task for formatting all js files with prettier
corasaurus-hex Feb 11, 2022
3b5d880
Update the PR template to include formatting
corasaurus-hex Feb 11, 2022
84237ac
Add an entry in the changelog to explain formatting
corasaurus-hex Feb 11, 2022
bfe6906
Make .prettierignore have a newline at EOF
corasaurus-hex Feb 11, 2022
218c118
Add a package.json script for format checks
corasaurus-hex Feb 11, 2022
32a8045
Try adding a prettier format check
corasaurus-hex Feb 11, 2022
26dcfa8
Actually execute the prettier-check build step
corasaurus-hex Feb 11, 2022
e44f807
Commit some bad formatting to ensure CI fails on bad formatting
corasaurus-hex Feb 11, 2022
6fd9fe5
Do not rewrite files, this is a check not a format
corasaurus-hex Feb 11, 2022
36d49b5
Use a slightly different cp command to restore build for prettier
corasaurus-hex Feb 11, 2022
65961c5
Try being more explicit about the destination path
corasaurus-hex Feb 11, 2022
401d886
List all files after the copy so we can debug what is happening
corasaurus-hex Feb 11, 2022
e0a8058
Try removing the working directory so we can copy the directory
corasaurus-hex Feb 11, 2022
a9f699e
Seems like it restores working directories between steps
corasaurus-hex Feb 11, 2022
64cd1fb
Try caching the build differently to capture dotfiles
corasaurus-hex Feb 11, 2022
7e11df4
fix broken formatting
corasaurus-hex Feb 11, 2022
9f1dac6
Fix all build restores such that they include dotfiles
corasaurus-hex Feb 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- run:
name: Copy build
command: |
cp -r * /tmp/build/
cp -r . /tmp/build
- save_cache:
name: Save dependencies
key: ts-{{ checksum "package.json" }}-cljs-{{ checksum "shadow-cljs.edn" }}-grammar-{{ checksum "src/calva-fmt/atom-language-clojure/package.json" }}
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
at: /tmp
- run:
name: Restore build
command: cp -r /tmp/build/* .
command: cp -rT /tmp/build ~/calva
- run:
name: Update system package lists
command: sudo apt-get update
Expand Down Expand Up @@ -128,6 +128,19 @@ jobs:
paths:
- ~/.atom/packages
- ./node_modules
prettier-check:
docker:
- image: circleci/node:latest
working_directory: ~/calva
steps:
- attach_workspace:
at: /tmp
- run:
name: Restore build
command: cp -rT /tmp/build ~/calva
- run:
name: Run prettier format check
command: npm run prettier-check
test-cljslib:
docker:
- image: circleci/node:latest
Expand All @@ -137,7 +150,7 @@ jobs:
at: /tmp
- run:
name: Restore build
command: cp -r /tmp/build/* .
command: cp -rT /tmp/build ~/calva
- run:
name: Run CLJS Tests
command: npm run calva-lib-test
Expand All @@ -152,7 +165,7 @@ jobs:
at: /tmp
- run:
name: Restore build
command: cp -r /tmp/build/* .
command: cp -rT /tmp/build ~/calva
- run:
name: Run TS Unit Tests
command: npm run unit-test
Expand All @@ -167,7 +180,7 @@ jobs:
at: /tmp
- run:
name: Restore build
command: cp -r /tmp/build/* .
command: cp -rT /tmp/build ~/calva
- run:
name: Compile Extension Tests
command: npm run compile-test
Expand All @@ -185,7 +198,7 @@ jobs:
at: /tmp
- run:
name: Restore build
command: cp -r /tmp/build/* .
command: cp -rT /tmp/build ~/calva
- run:
name: "Publish Release on GitHub"
command: |
Expand Down Expand Up @@ -217,7 +230,7 @@ jobs:
at: /tmp
- run:
name: Restore build
command: cp -r /tmp/build/* .
command: cp -rT /tmp/build ~/calva
- run:
name: Publish to the marketplace
command: |
Expand All @@ -237,7 +250,7 @@ jobs:
at: /tmp
- run:
name: Restore build
command: cp -r /tmp/build/* .
command: cp -rT /tmp/build ~/calva
- run:
name: Publish to Open VSX
command: |
Expand Down Expand Up @@ -323,6 +336,9 @@ workflows:
filters:
tags:
ignore: /^v\d+\.\d+\.\d+-?.*/
- prettier-check:
requires:
- build
- test-grammar:
requires:
- build
Expand All @@ -343,6 +359,14 @@ workflows:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+-?.*/
- prettier-check:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+-?.*/
- test-grammar:
requires:
- build
Expand Down Expand Up @@ -377,6 +401,7 @@ workflows:
only: /^v\d+\.\d+\.\d+-?.*/
- github-release:
requires:
- prettier-check
- test-grammar
- test-cljslib
- test-integration
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
/.shadow-cljs
/out
/.vscode-test
/.vscode
/.lsp
/.clj-kondo
27 changes: 27 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"endOfLine": "lf",
"embeddedLanguageFormatting": "auto",
"overrides": [
{
"files": [
"*.css"
],
"options": {
"singleQuote": false
}
}
]
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- Maintenance: [Consistently format all JavaScript and TypeScript in the project and provide for easily formatting these files in the future.](https://github.com/BetterThanTomorrow/calva/pull/1524)

## [2.0.240] - 2022-02-06
- Maintenance: [Update dependencies to fix security vulnerabilities](https://github.com/BetterThanTomorrow/calva/pull/1520)

Expand Down
1 change: 1 addition & 0 deletions docs/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ I have:
- [ ] If I am fixing the issue, I have used [GitHub's fixes/closes syntax](https://help.github.com/en/articles/closing-issues-using-keywords)
- [ ] If I am fixing just part of the issue, I have just referenced it w/o any of the "fixes” keywords.
- [ ] Created the issue I am fixing/addressing, if it was not present.
- [ ] Formatted all JavaScript and TypeScript code that was changed. (use the [prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) or run `npm run prettier-format`)

<!-- This is a nice book to read about the power of checklists: https://www.samuelthomasdavies.com/book-summaries/health-fitness/the-checklist-manifesto/ -->

Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,9 @@
"calva-lib-test": "node ./out/cljs-lib/test/cljs-lib-tests.js",
"integration-test": "node ./out/extension-test/integration/runTests.js",
"unit-test": "npx mocha --require ts-node/register 'src/extension-test/unit/**/*-test.ts'",
"publish": "bb publish.clj"
"publish": "bb publish.clj",
"prettier-format": "npx prettier --write './**/*.{ts,js}'",
"prettier-check": "npx prettier --check './**/*.{ts,js}'"
},
"dependencies": {
"@types/escape-html": "0.0.20",
Expand Down Expand Up @@ -2637,6 +2639,7 @@
"node-gyp": "^8.4.1",
"nodemon": "^2.0.3",
"ovsx": "^0.3.0",
"prettier": "2.5.1",
"rimraf": "^2.7.1",
"shadow-cljs": "^2.11.18",
"source-map-support": "^0.5.16",
Expand All @@ -2652,4 +2655,4 @@
"webpack": "^5.27.1",
"webpack-cli": "^4.5.0"
}
}
}
153 changes: 87 additions & 66 deletions src/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,87 @@
import * as vscode from 'vscode';
import * as UA from 'universal-analytics';
import * as uuid from "uuidv4";
import * as os from 'os';

// var debug = require('debug');
// debug.log = console.info.bind(console);


function userAllowsTelemetry(): boolean {
const config = vscode.workspace.getConfiguration('telemetry');
return config.get<boolean>('enableTelemetry', false);
}

export default class Analytics {
private visitor: UA.Visitor;
private extension: vscode.Extension<any>;
private extensionVersion: string;
private store: vscode.Memento;
private GA_ID = (process.env.CALVA_DEV_GA ? process.env.CALVA_DEV_GA : 'FUBAR-69796730-3').replace(/^FUBAR/, "UA");

constructor(context: vscode.ExtensionContext) {
this.extension = vscode.extensions.getExtension("betterthantomorrow.calva")!;
this.extensionVersion = this.extension.packageJSON.version;
this.store = context.globalState;

this.visitor = UA(this.GA_ID, this.userID());
this.visitor.set("cd1", this.extensionVersion);
this.visitor.set("cd2", vscode.version);
this.visitor.set("cd3", this.extensionVersion);
this.visitor.set("cd4", `${os.platform()}/${os.release()}`);
this.visitor.set("cn", `calva-${this.extensionVersion}`);
this.visitor.set("ua", `Calva/${this.extensionVersion} (${os.platform()}; ${os.release()}; ${os.type}) VSCode/${vscode.version}`);
}

private userID(): string {
const KEY = 'userLogID';
if (this.store.get(KEY) == undefined) {
const newID = uuid.uuid();
this.store.update(KEY, newID)
return newID;
} else {
return this.store.get(KEY);
}
}

logPath(path: string): Analytics {
if (userAllowsTelemetry()) {
this.visitor.pageview(path);
}
return this;
}

logEvent(category: string, action: string, label?: string, value?: string): Analytics {
if (userAllowsTelemetry()) {
this.visitor.event({ ec: category, ea: action, el: label, ev: value });
}
return this;
}

send() {
if (userAllowsTelemetry()) {
this.visitor.send();
}
}
}
import * as vscode from 'vscode';
import * as UA from 'universal-analytics';
import * as uuid from 'uuidv4';
import * as os from 'os';

// var debug = require('debug');
// debug.log = console.info.bind(console);

function userAllowsTelemetry(): boolean {
const config = vscode.workspace.getConfiguration('telemetry');
return config.get<boolean>('enableTelemetry', false);
}

export default class Analytics {
private visitor: UA.Visitor;
private extension: vscode.Extension<any>;
private extensionVersion: string;
private store: vscode.Memento;
private GA_ID = (process.env.CALVA_DEV_GA
? process.env.CALVA_DEV_GA
: 'FUBAR-69796730-3'
).replace(/^FUBAR/, 'UA');

constructor(context: vscode.ExtensionContext) {
this.extension = vscode.extensions.getExtension(
'betterthantomorrow.calva'
)!;
this.extensionVersion = this.extension.packageJSON.version;
this.store = context.globalState;

this.visitor = UA(this.GA_ID, this.userID());
this.visitor.set('cd1', this.extensionVersion);
this.visitor.set('cd2', vscode.version);
this.visitor.set('cd3', this.extensionVersion);
this.visitor.set('cd4', `${os.platform()}/${os.release()}`);
this.visitor.set('cn', `calva-${this.extensionVersion}`);
this.visitor.set(
'ua',
`Calva/${
this.extensionVersion
} (${os.platform()}; ${os.release()}; ${os.type}) VSCode/${
vscode.version
}`
);
}

private userID(): string {
const KEY = 'userLogID';
if (this.store.get(KEY) == undefined) {
const newID = uuid.uuid();
this.store.update(KEY, newID);
return newID;
} else {
return this.store.get(KEY);
}
}

logPath(path: string): Analytics {
if (userAllowsTelemetry()) {
this.visitor.pageview(path);
}
return this;
}

logEvent(
category: string,
action: string,
label?: string,
value?: string
): Analytics {
if (userAllowsTelemetry()) {
this.visitor.event({
ec: category,
ea: action,
el: label,
ev: value,
});
}
return this;
}

send() {
if (userAllowsTelemetry()) {
this.visitor.send();
}
}
}
Loading