Skip to content

Commit 59de345

Browse files
committed
Add makie plugin for linting TypeScript declaration files
1 parent 8a0c007 commit 59de345

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

etc/.makie.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ plugins[ 'lint-javascript' ] = path.join( prefix, 'makie-lint-javascript' );
4444
plugins[ 'lint-markdown' ] = path.join( prefix, 'makie-lint-markdown' );
4545
plugins[ 'lint-python' ] = path.join( prefix, 'makie-lint-python' );
4646
plugins[ 'lint-r' ] = path.join( prefix, 'makie-lint-r' );
47+
plugins[ 'lint-typescript-declarations' ] = path.join( prefix, 'makie-lint-typescript-declarations' );
4748
plugins[ 'list-pkgs' ] = path.join( prefix, 'makie-list-pkgs' );
4849
plugins[ 'list-pkgs-names' ] = path.join( prefix, 'makie-list-pkgs-names' );
4950
plugins[ 'markdown-asset-link' ] = path.join( prefix, 'makie-markdown-asset-link' );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var spawn = require( 'child_process' ).spawn;
24+
25+
26+
// FUNCTIONS //
27+
28+
/**
29+
* Callback invoked upon encountering an error.
30+
*
31+
* @private
32+
* @param {Error} error - error object
33+
*/
34+
function onError( error ) {
35+
process.exitCode = 1;
36+
console.error( 'Error: %s', error.message ); // eslint-disable-line no-console
37+
}
38+
39+
/**
40+
* Callback invoked upon child process close.
41+
*
42+
* @private
43+
* @param {number} code - exit code
44+
* @returns {void}
45+
*/
46+
function onFinish( code ) {
47+
if ( code !== 0 ) {
48+
process.exitCode = code;
49+
return console.error( 'Child process exited with code `'+code + '`.' ); // eslint-disable-line no-console
50+
}
51+
}
52+
53+
/**
54+
* Callback invoked upon receiving data from `stdout`.
55+
*
56+
* @private
57+
* @param {Buffer} data - standard output
58+
*/
59+
function stdout( data ) {
60+
process.stdout.write( data );
61+
}
62+
63+
/**
64+
* Callback invoked upon receiving data from `stderr`.
65+
*
66+
* @private
67+
* @param {Buffer} data - standard error
68+
*/
69+
function stderr( data ) {
70+
process.stderr.write( data );
71+
}
72+
73+
74+
// MAIN //
75+
76+
/**
77+
* Plugin to lint TypeScript declaration files.
78+
*
79+
* @param {string} dir - Makefile directory
80+
* @param {string} cwd - current working directory
81+
* @param {string} subpath - subdirectory path
82+
*/
83+
function plugin( dir, cwd, subpath ) {
84+
var opts;
85+
var args;
86+
var proc;
87+
88+
opts = {};
89+
opts.cwd = dir;
90+
91+
args = [];
92+
93+
// Environment variables:
94+
if ( subpath ) {
95+
args.push( 'TYPESCRIPT_DECLARATIONS_FILTER=.*/'+subpath+'/.*' );
96+
}
97+
// Target:
98+
args.push( 'lint-typescript-declarations' );
99+
100+
proc = spawn( 'make', args, opts );
101+
proc.on( 'error', onError );
102+
proc.stdout.on( 'data', stdout );
103+
proc.stderr.on( 'data', stderr );
104+
proc.on( 'close', onFinish );
105+
}
106+
107+
108+
// EXPORTS //
109+
110+
module.exports = plugin;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@stdlib/_tools/makie/plugins/makie-lint-typescript-declarations",
3+
"version": "0.0.0",
4+
"description": "makie plugin to lint TypeScript declaration files.",
5+
"author": {
6+
"name": "The Stdlib Authors",
7+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
8+
},
9+
"contributors": [
10+
{
11+
"name": "The Stdlib Authors",
12+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
13+
}
14+
],
15+
"scripts": {},
16+
"main": "./lib",
17+
"repository": {
18+
"type": "git",
19+
"url": "git://github.com/stdlib-js/stdlib.git"
20+
},
21+
"homepage": "https://github.com/stdlib-js/stdlib",
22+
"keywords": [
23+
"tools",
24+
"makie",
25+
"make",
26+
"makefile",
27+
"plugin",
28+
"lint",
29+
"typescript",
30+
"ts",
31+
"declarations",
32+
"declaration",
33+
"definitions",
34+
"definition"
35+
],
36+
"bugs": {
37+
"url": "https://github.com/stdlib-js/stdlib/issues"
38+
},
39+
"dependencies": {},
40+
"devDependencies": {},
41+
"engines": {
42+
"node": ">=0.10.0",
43+
"npm": ">2.7.0"
44+
},
45+
"license": "Apache-2.0"
46+
}

0 commit comments

Comments
 (0)