Scripts linted

This commit is contained in:
Angelos Chalaris
2018-08-03 10:49:29 +03:00
parent 37da7ac424
commit d9593cdce5
13 changed files with 525 additions and 233 deletions

View File

@ -14,45 +14,73 @@ let snippetsArchiveData = require('../snippet_data/snippetsArchive.json');
const OUTPUT_PATH = './snippet_data';
console.time('Analyzer');
// Read data
let snippetTokens = {data: snippetsData.data.map(snippet => {
let tokens = prism.tokenize(snippet.attributes.codeBlocks[0], prism.languages.javascript, 'javascript');
return {
id: snippet.id,
type: 'snippetAnalysis',
attributes: {
codeLength: snippet.attributes.codeBlocks[0].trim().length,
tokenCount: tokens.length,
functionCount: tokens.filter(t => t.type === 'function').length,
operatorCount: tokens.filter(t => t.type === 'operator').length,
keywordCount: tokens.filter(t => t.type === 'keyword').length,
distinctFunctionCount: [...new Set(tokens.filter(t => t.type === 'function').map(t => t.content))].length
},
meta: {
hash: snippet.meta.hash
}
};
}), meta: { specification: "http://jsonapi.org/format/"}};
let snippetArchiveTokens = {data: snippetsArchiveData.data.map(snippet => {
let tokens = prism.tokenize(snippet.attributes.codeBlocks[0], prism.languages.javascript, 'javascript');
return {
id: snippet.id,
type: 'snippetAnalysis',
attributes: {
codeLength: snippet.attributes.codeBlocks[0].trim().length,
tokenCount: tokens.length,
functionCount: tokens.filter(t => t.type === 'function').length,
operatorCount: tokens.filter(t => t.type === 'operator').length,
keywordCount: tokens.filter(t => t.type === 'keyword').length,
distinctFunctionCount: [...new Set(tokens.filter(t => t.type === 'function').map(t => t.content))].length
},
meta: {
hash: snippet.meta.hash
}
};
}), meta: { specification: "http://jsonapi.org/format/"}};
let snippetTokens = {
data: snippetsData.data.map(snippet => {
let tokens = prism.tokenize(
snippet.attributes.codeBlocks[0],
prism.languages.javascript,
'javascript'
);
return {
id: snippet.id,
type: 'snippetAnalysis',
attributes: {
codeLength: snippet.attributes.codeBlocks[0].trim().length,
tokenCount: tokens.length,
functionCount: tokens.filter(t => t.type === 'function').length,
operatorCount: tokens.filter(t => t.type === 'operator').length,
keywordCount: tokens.filter(t => t.type === 'keyword').length,
distinctFunctionCount: [
...new Set(tokens.filter(t => t.type === 'function').map(t => t.content))
].length
},
meta: {
hash: snippet.meta.hash
}
};
}),
meta: { specification: 'http://jsonapi.org/format/' }
};
let snippetArchiveTokens = {
data: snippetsArchiveData.data.map(snippet => {
let tokens = prism.tokenize(
snippet.attributes.codeBlocks[0],
prism.languages.javascript,
'javascript'
);
return {
id: snippet.id,
type: 'snippetAnalysis',
attributes: {
codeLength: snippet.attributes.codeBlocks[0].trim().length,
tokenCount: tokens.length,
functionCount: tokens.filter(t => t.type === 'function').length,
operatorCount: tokens.filter(t => t.type === 'operator').length,
keywordCount: tokens.filter(t => t.type === 'keyword').length,
distinctFunctionCount: [
...new Set(tokens.filter(t => t.type === 'function').map(t => t.content))
].length
},
meta: {
hash: snippet.meta.hash
}
};
}),
meta: { specification: 'http://jsonapi.org/format/' }
};
// Write data
fs.writeFileSync(path.join(OUTPUT_PATH, 'snippetAnalytics.json'), JSON.stringify(snippetTokens, null, 2));
fs.writeFileSync(path.join(OUTPUT_PATH, 'snippetArchiveAnalytics.json'), JSON.stringify(snippetArchiveTokens, null, 2));
fs.writeFileSync(
path.join(OUTPUT_PATH, 'snippetAnalytics.json'),
JSON.stringify(snippetTokens, null, 2)
);
fs.writeFileSync(
path.join(OUTPUT_PATH, 'snippetArchiveAnalytics.json'),
JSON.stringify(snippetArchiveTokens, null, 2)
);
// Display messages and time
console.log(`${chalk.green('SUCCESS!')} snippetAnalyticss.json and snippetArchiveAnalytics.json files generated!`);
console.log(
`${chalk.green(
'SUCCESS!'
)} snippetAnalyticss.json and snippetArchiveAnalytics.json files generated!`
);
console.timeEnd('Analyzer');