Skip to content

Commit

Permalink
Ninja updated to ESLint and the new yo template layout
Browse files Browse the repository at this point in the history
To create a valid extension for publishing I needed to update stuff
  • Loading branch information
oderwat committed Dec 28, 2020
1 parent a8c564d commit d22d792
Show file tree
Hide file tree
Showing 12 changed files with 4,229 additions and 1,787 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
out
dist
node_modules
extension.js
.vscode-test/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ Skip error highlighting for some or all languages. For example, you may want to
"haskell"
]
```

If error color is disabled, indent colors will be rendered until the length of rendered characters (white spaces, tabs, and other ones) is divisible by tabsize. Turn on this option to render white spaces and tabs only.

```js
"indentRainbow.colorOnWhiteSpaceOnly": true // false is the default
```

Build with:

```
Expand Down
Binary file removed indent-rainbow-7.4.0.vsix
Binary file not shown.
Binary file added indent-rainbow-7.5.0.vsix
Binary file not shown.
5,852 changes: 4,095 additions & 1,757 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 19 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "indent-rainbow",
"description": "Makes indentation easier to read",
"version": "7.4.0",
"version": "7.5.0",
"publisher": "oderwat",
"author": {
"name": "Hans Raaf"
},
"icon": "assets/icon.png",
"license": "MIT",
"engines": {
"vscode": "0.10.x"
"vscode": "^1.52.0"
},
"repository": {
"url": "https://github.com/oderwat/vscode-indent-rainbow.git",
Expand Down Expand Up @@ -96,16 +96,24 @@
},
"main": "./out/extension",
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/node": "^6.0.40",
"typescript": "^2.0.3",
"vscode": "^1.1.30"
},
"dependencies": {
"vsce": "^1.57.1"
"@types/glob": "^7.1.3",
"@types/mocha": "^8.0.4",
"@types/node": "^12.11.7",
"@types/vscode": "^1.52.0",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"eslint": "^7.16.0",
"glob": "^7.1.6",
"mocha": "^8.1.3",
"typescript": "^4.1.2",
"vscode-test": "^1.4.1"
}
}
18 changes: 11 additions & 7 deletions extension.ts → src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export function activate(context: vscode.ExtensionContext) {

const tabmix_color = vscode.workspace.getConfiguration('indentRainbow')['tabmixColor'] || "";
const tabmix_decoration_type = "" !== tabmix_color ? vscode.window.createTextEditorDecorationType({
backgroundColor: tabmix_color
backgroundColor: tabmix_color
}) : null;

const ignoreLinePatterns = vscode.workspace.getConfiguration('indentRainbow')['ignoreLinePatterns'] || [];
const colorOnWhiteSpaceOnly = vscode.workspace.getConfiguration('indentRainbow')['colorOnWhiteSpaceOnly'];
const colorOnWhiteSpaceOnly = vscode.workspace.getConfiguration('indentRainbow')['colorOnWhiteSpaceOnly'] || false;

// Colors will cycle through, and can be any size that you want
const colors = vscode.workspace.getConfiguration('indentRainbow')['colors'] || [
Expand Down Expand Up @@ -154,8 +154,12 @@ export function activate(context: vscode.ExtensionContext) {
}
var regEx = /^[\t ]+/gm;
var text = activeEditor.document.getText();
var tabsize = activeEditor.options.tabSize;
var tabs = " ".repeat(tabsize);
var tabSizeRaw = activeEditor.options.tabSize;
var tabSize = 4
if(tabSizeRaw !== 'auto') {
tabSize=+tabSizeRaw
}
var tabs = " ".repeat(tabSize);
const ignoreLines = [];
let error_decorator: vscode.DecorationOptions[] = [];
let tabmix_decorator: vscode.DecorationOptions[] = tabmix_decoration_type ? []: null;
Expand Down Expand Up @@ -189,7 +193,7 @@ export function activate(context: vscode.ExtensionContext) {
const pos = activeEditor.document.positionAt(match.index);
const line = activeEditor.document.lineAt(pos).lineNumber;
let skip = skipAllErrors || ignoreLines.indexOf(line) !== -1; // true if the lineNumber is in ignoreLines.
var thematch = match[0];
var thematch = match[0];
var ma = (match[0].replace(re, tabs)).length;
/**
* Error handling.
Expand All @@ -198,7 +202,7 @@ export function activate(context: vscode.ExtensionContext) {
* Checks for lines being ignored in ignoreLines array ( `skip` Boolran)
* before considering the line an error.
*/
if(!skip && ma % tabsize !== 0) {
if(!skip && ma % tabSize !== 0) {
var startPos = activeEditor.document.positionAt(match.index);
var endPos = activeEditor.document.positionAt(match.index + match[0].length);
var decoration = { range: new vscode.Range(startPos, endPos), hoverMessage: null };
Expand All @@ -214,7 +218,7 @@ export function activate(context: vscode.ExtensionContext) {
if(m[n] === "\t") {
n++;
} else {
n+=activeEditor.options.tabSize;
n+=tabSize;
}
if (colorOnWhiteSpaceOnly && n > l) {
n = l
Expand Down
23 changes: 23 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from 'path';

import { runTests } from 'vscode-test';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
15 changes: 15 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});
38 changes: 38 additions & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
color: true
});

const testsRoot = path.resolve(__dirname, '..');

return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}
12 changes: 0 additions & 12 deletions tslint.json

This file was deleted.

0 comments on commit d22d792

Please sign in to comment.