From the Massachusetts tax instruction booklet:
You must file Massachusetts Form 1-NR/PY, Nonresident/Part-Year Resident Income Tax Return if you were not a resident of Massachusetts for any part of the year and the lesser of either:
1. Your Massachusetts source income was more than $8,000; or
2. Your Massachusetts source income was more than your personal exemption amount multiplied by the ratio of your Massachusetts income to your total income.
You also must file Form 1-NR/PY if you were a resident of Massachusetts for part of the year and you had more than $8,000 in gross income during that time, whether received from sources inside or outside of Massachusetts.
https://www.mass.gov/files/documents/2019/01/18/dor-2018-form-1-nrpy-instructions.pdf
**Answers are correct to the best of my ability but do not constitute tax or legal advice.