Skip to content

Commit 405e1d5

Browse files
pauldrucePrabhakar Kumar
authored andcommitted
Adding linting for labextension code.
1 parent 7edae89 commit 405e1d5

File tree

3 files changed

+104
-63
lines changed

3 files changed

+104
-63
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
{
3+
"root": true,
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"ecmaVersion": 6,
7+
"sourceType": "module"
8+
},
9+
"plugins": ["@typescript-eslint"],
10+
"extends": ["standard"],
11+
"rules": {
12+
"indent": ["error", 4, { "SwitchCase": 1 }],
13+
"semi": ["error", "always"],
14+
"no-extra-semi": "error",
15+
"quote-props": "warn",
16+
"dot-notation": "warn",
17+
"object-curly-newline": "warn",
18+
"multiline-ternary": "warn",
19+
"prefer-const": "warn",
20+
"no-prototype-builtins": "warn",
21+
"array-callback-return": "warn",
22+
"array-bracket-spacing": "warn",
23+
"quotes": "warn",
24+
"lines-between-class-members": "warn",
25+
"no-empty": "warn",
26+
"prefer-regex-literals": "warn",
27+
"no-useless-catch": "warn",
28+
"no-case-declarations": "warn",
29+
"computed-property-spacing": "warn",
30+
"no-async-promise-executor": "warn",
31+
"no-unused-vars": "warn",
32+
"no-unreachable-loop": "warn",
33+
"no-void": "warn",
34+
"import/no-webpack-loader-syntax": "warn",
35+
"node/no-callback-literal": ["off", "warn"],
36+
"node/handle-callback-err": ["off", "warn"],
37+
"node/no-deprecated-api": ["off", "warn"]
38+
}
39+
}
40+
41+

src/jupyter_matlab_labextension/src/matlab_cm_mode.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ import { ICodeMirror } from '@jupyterlab/codemirror';
1111
/** Of the default codemirror tokens, "keyword" matches MATLAB comment style best,
1212
* and variable-2 matches MATLAB keyword style best. These tokens are only used for
1313
* display and not for execution. */
14-
export const token_to_matlab_style = new Map<string, string>([
15-
["comment", "keyword"],
16-
["string", "string-2"],
17-
["keyword", "variable-2"]
14+
export const tokenToMatlabStyle = new Map<string, string>([
15+
['comment', 'keyword'],
16+
['string', 'string-2'],
17+
['keyword', 'variable-2']
1818
]);
1919

2020
const baseRegex = [
2121
/** The boolean "sol" is needed as the ^ regexp marker is not
2222
* sufficient in this context.
2323
* See https://codemirror.net/5/demo/simplemode.html. */
24-
{ regex: /([\s]*)(%\{)[^\S\n]*$/, token: token_to_matlab_style.get("comment"), next: 'comment', sol: true },
25-
{ regex: /%.*$/, token: token_to_matlab_style.get("comment") },
26-
{ regex: /".*?("|$)/, token: token_to_matlab_style.get("string") },
27-
{ regex: /'.*?('|$)/, token: token_to_matlab_style.get("string") },
28-
{ regex: /\b(break|case|classdef|continue|global|otherwise|persistent|return|spmd)\b/, token: token_to_matlab_style.get("keyword") },
24+
{ regex: /([\s]*)(%\{)[^\S\n]*$/, token: tokenToMatlabStyle.get('comment'), next: 'comment', sol: true },
25+
{ regex: /%.*$/, token: tokenToMatlabStyle.get('comment') },
26+
{ regex: /".*?("|$)/, token: tokenToMatlabStyle.get('string') },
27+
{ regex: /'.*?('|$)/, token: tokenToMatlabStyle.get('string') },
28+
{ regex: /\b(break|case|classdef|continue|global|otherwise|persistent|return|spmd)\b/, token: tokenToMatlabStyle.get('keyword') },
2929
{ regex: /(\bimport\b)(.*)(?=;|%|$)/, token: ['variable', 'meta', 'variable'] },
30-
{ regex: /\b(arguments|enumeration|events|for|function|if|methods|parfor|properties|try|while)\b/, indent: true, token: token_to_matlab_style.get("keyword") },
31-
{ regex: /\b(switch)\b/, indent: true, token: token_to_matlab_style.get("keyword") },
32-
{ regex: /\b(catch|else|elseif)\b/, indent: true, dedent: true, token: token_to_matlab_style.get("keyword") },
33-
{ regex: /\b(?:end)\b/, dedent: true, token: token_to_matlab_style.get("keyword") },
30+
{ regex: /\b(arguments|enumeration|events|for|function|if|methods|parfor|properties|try|while)\b/, indent: true, token: tokenToMatlabStyle.get('keyword') },
31+
{ regex: /\b(switch)\b/, indent: true, token: tokenToMatlabStyle.get('keyword') },
32+
{ regex: /\b(catch|else|elseif)\b/, indent: true, dedent: true, token: tokenToMatlabStyle.get('keyword') },
33+
{ regex: /\b(?:end)\b/, dedent: true, token: tokenToMatlabStyle.get('keyword') },
3434
/** Removing this line (or adding \s* around it) will break tab completion. */
35-
{ regex: /[a-zA-Z_]\w*/, token: "variable" }
35+
{ regex: /[a-zA-Z_]\w*/, token: 'variable' }
3636
];
3737

3838
const startRegex = baseRegex;
3939
const multilineCommentRegex = [
40-
{ regex: /([\s]*)(%\})[^\S\n]*(?:$)/, token: token_to_matlab_style.get("comment"), next: 'start', sol: true },
41-
{ regex: /.*/, token: token_to_matlab_style.get("comment") }
40+
{ regex: /([\s]*)(%\})[^\S\n]*(?:$)/, token: tokenToMatlabStyle.get('comment'), next: 'start', sol: true },
41+
{ regex: /.*/, token: tokenToMatlabStyle.get('comment') }
4242
];
4343

4444
/** Install mode in CodeMirror */
@@ -71,7 +71,7 @@ export const matlabCodeMirrorPlugin: JupyterFrontEndPlugin<void> = {
7171
requires: [ICodeMirror],
7272
activate: (
7373
app: JupyterFrontEnd,
74-
codeMirror: ICodeMirror,
74+
codeMirror: ICodeMirror
7575
) => {
7676
defineMATLABMode(codeMirror);
7777
}

src/jupyter_matlab_labextension/src/matlab_files.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,59 @@ const FACTORY = 'Editor';
2020
const PALETTE_CATEGORY = 'Other';
2121
const command = 'matlab:new-matlab-file';
2222

23-
function registerMFiles ( app: JupyterFrontEnd, launcher: ILauncher | null, palette: ICommandPalette | null) {
24-
const { commands } = app;
25-
const createNewMatlabFile = async (args: ReadonlyPartialJSONObject) => {
26-
/** Get the directory in which the MATLAB file must be created;
23+
function registerMFiles (app: JupyterFrontEnd, launcher: ILauncher | null, palette: ICommandPalette | null) {
24+
const { commands } = app;
25+
const createNewMatlabFile = async (args: ReadonlyPartialJSONObject) => {
26+
/** Get the directory in which the MATLAB file must be created;
2727
* otherwise take the current filebrowser directory. */
28-
const cwd = args.cwd;
28+
const cwd = args.cwd;
2929

30-
/** Create a new untitled MATLAB file. */
31-
const model = await commands.execute('docmanager:new-untitled', {
32-
path: cwd,
33-
type: 'file',
34-
ext: '.m'
35-
});
30+
/** Create a new untitled MATLAB file. */
31+
const model = await commands.execute('docmanager:new-untitled', {
32+
path: cwd,
33+
type: 'file',
34+
ext: '.m'
35+
});
3636

37-
/** Open the newly created file with the 'Editor'. */
38-
return commands.execute('docmanager:open', {
39-
path: model.path,
40-
factory: FACTORY
41-
});
42-
}
43-
/** Create a new MATLAB file by adding a command to the JupyterFrontEnd. */
44-
commands.addCommand(command, {
45-
label: (args) => (args.isPalette ? 'New MATLAB File' : 'MATLAB File'),
46-
caption: 'Create a new MATLAB file',
47-
icon: (args) => (args.isPalette ? '' : newMFileIcon),
48-
execute: createNewMatlabFile
37+
/** Open the newly created file with the 'Editor'. */
38+
return commands.execute('docmanager:open', {
39+
path: model.path,
40+
factory: FACTORY
4941
});
42+
};
43+
/** Create a new MATLAB file by adding a command to the JupyterFrontEnd. */
44+
commands.addCommand(command, {
45+
label: (args) => (args.isPalette ? 'New MATLAB File' : 'MATLAB File'),
46+
caption: 'Create a new MATLAB file',
47+
icon: (args) => (args.isPalette ? '' : newMFileIcon),
48+
execute: createNewMatlabFile
49+
});
5050

51-
/** Add the command to the launcher. */
52-
if (launcher) {
53-
launcher.add({
54-
command,
55-
category: 'Other',
56-
rank: 1
57-
});
58-
}
51+
/** Add the command to the launcher. */
52+
if (launcher) {
53+
launcher.add({
54+
command,
55+
category: 'Other',
56+
rank: 1
57+
});
58+
}
5959

60-
/** Add the command to the palette. */
61-
if (palette) {
62-
palette.addItem({
63-
command,
64-
args: { isPalette: true },
65-
category: PALETTE_CATEGORY
66-
});
67-
}
68-
/** Associate file type with icon. */
69-
app.docRegistry.addFileType({
70-
name: 'MATLAB',
71-
displayName: 'MATLAB File',
72-
extensions: ['.m'],
73-
mimeTypes: ['text/x-matlab', 'matlab'],
74-
icon: matlabIcon
60+
/** Add the command to the palette. */
61+
if (palette) {
62+
palette.addItem({
63+
command,
64+
args: { isPalette: true },
65+
category: PALETTE_CATEGORY
7566
});
67+
}
68+
/** Associate file type with icon. */
69+
app.docRegistry.addFileType({
70+
name: 'MATLAB',
71+
displayName: 'MATLAB File',
72+
extensions: ['.m'],
73+
mimeTypes: ['text/x-matlab', 'matlab'],
74+
icon: matlabIcon
75+
});
7676
}
7777

7878
export const matlabMFilesPlugin: JupyterFrontEndPlugin<void> = {

0 commit comments

Comments
 (0)