-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prettier-plugin-jsdoc): add function to create language definitions
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @typedef {LinguistLanguageProperties & LanguageSharedProperties} LinguistLanguage | ||
*/ | ||
|
||
/** | ||
* @typedef {LanguagePrivateProperties & LanguageSharedProperties & LanguageProperties} Language | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} LinguistLanguageProperties | ||
* @property {number} languageId A unique identifier for the language. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} LanguageSharedProperties | ||
* @property {string[]} extensions The extensions of files that related to the language. | ||
* @property {string[]} [aliases] A list of known aliases for the language. | ||
* @property {string[]} [filenames] An Array of filenames commonly associated with the language. | ||
* @see https://github.com/github/linguist/blob/master/lib/linguist/languages.yml | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} LanguagePrivateProperties | ||
* @property {number} linguistLanguageId The unique ID for the language on Linguist. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} LanguageProperties | ||
* @property {string} since Since which version of Prettier it can be used. | ||
* @property {string[]} parsers The list of parsers that can parse the language. | ||
* @property {string[]} vscodeLanguageIds The ID for the language on VSCode. | ||
*/ | ||
|
||
/** | ||
* @typedef {LanguageProperties & Partial<LanguageSharedProperties>} LanguageOverrides | ||
*/ | ||
|
||
/** | ||
* Creates the language definition for Prettier. | ||
* | ||
* @param {LinguistLanguage} linguistLanguage The base data for the language that will be used. | ||
* @param {LanguageOverrides} overrides The information of the language for Prettier, and | ||
* possible overrides for the Linguist data. | ||
* @returns {Language} | ||
*/ | ||
const createLanguage = (linguistLanguage, overrides) => { | ||
const { languageId, ...rest } = linguistLanguage; | ||
return { | ||
linguistLanguageId: languageId, | ||
...rest, | ||
...overrides, | ||
}; | ||
}; | ||
|
||
module.exports.createLanguage = createLanguage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
jest.unmock('../../src/fns/createLanguage'); | ||
|
||
const { createLanguage } = require('../../src/fns/createLanguage'); | ||
|
||
describe('createLanguage', () => { | ||
it('should create a language definition for Prettier', () => { | ||
// Given | ||
const linguistLanguage = { | ||
languageId: 2509, | ||
extensions: ['.js'], | ||
}; | ||
const overrides = { | ||
since: '0.0.0', | ||
parsers: ['babel'], | ||
vscodeLanguageIds: ['javascript'], | ||
}; | ||
const output = { | ||
linguistLanguageId: 2509, | ||
extensions: ['.js'], | ||
since: '0.0.0', | ||
parsers: ['babel'], | ||
vscodeLanguageIds: ['javascript'], | ||
}; | ||
let result = null; | ||
// When | ||
result = createLanguage(linguistLanguage, overrides); | ||
// Then | ||
expect(result).toEqual(output); | ||
}); | ||
}); |